const 和非常量函数的重载如何工作?

How does overloading of const and non-const functions work?(const 和非常量函数的重载如何工作?)
本文介绍了const 和非常量函数的重载如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!


STL 充满了这样的定义:

iterator begin ();
const_iterator begin () const;


As return value does not participate in overloading resolution, the only difference here is the function being const. Is this part of the overloading mechanism? What is the compiler's algorithm for resolving a line like:

vector<int>::const_iterator it = myvector.begin();



vector<int>::const_iterator it = myvector.begin();

如果 myvector 不是 const,begin() 的非常量版本将被调用,您将依赖从迭代器到 const_iterator 的隐式转换.

if myvector isn't const the non-const version of begin() will be called and you will be relying on an implicit conversion from iterator to const_iterator.

这篇关于const 和非常量函数的重载如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



Why does C++ compilation take so long?(为什么 C++ 编译需要这么长时间?)
Why is my program slow when looping over exactly 8192 elements?(为什么我的程序在循环 8192 个元素时很慢?)
C++ performance challenge: integer to std::string conversion(C++ 性能挑战:整数到 std::string 的转换)
Fast textfile reading in c++(在 C++ 中快速读取文本文件)
Is it better to use std::memcpy() or std::copy() in terms to performance?(就性能而言,使用 std::memcpy() 或 std::copy() 更好吗?)
Does the C++ standard mandate poor performance for iostreams, or am I just dealing with a poor implementation?(C++ 标准是否要求 iostreams 性能不佳,或者我只是在处理一个糟糕的实现?)