msc*_*msc 6 c++ const function c++11 c++14
我有重载const
和non-const
c ++结构的功能.然后,我运行程序,我想知道,它没有模棱两可的错误工作正常.
#include <iostream>
struct St
{
int f() const
{
return 1;
}
int f()
{
return 2;
}
} s;
int main()
{
int ret = s.f();
std::cout<<ret<<std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
所以,我只是想知道,为什么编译器不会给"const"和"not-const"函数带来模糊错误?
在这种情况下,编译器确定该结构体不具有重载函数返回类型(由于不明确,这是不允许的)当然,),而是具有不同 \xe2\x80\x9cconstness 的重载函数;\xe2\x80\x9d 是一个术语在其他答案之一中,这里有意义。
\n\n至于没有编译器错误:
\n\n希望有帮助!
\n