为什么允许成员函数参数const不匹配?

时间:2017-11-29 13:18:34

标签: c++ visual-studio gcc

为什么这会编译?虽然签名不同?

class A { void f(const int  a); };
void A::f(int a) {} //compiles fine

我还尝试了其他签名类型,结果好坏参与:

//Doesn't Compile:
class A { void f(const int*  a); };
void A::f(int* a) {}

class B { void f(const int&  a); };
void B::f(int& a) {}

//Compiles:
class C { void f(int* const  a); };
void C::f(int* a) {}

class D { void f(int& const  a); };
void D::f(int& a) {}

为什么?
在C ++规范/标准中,编写的const在这些情况下并不重要吗?

我已经检查过Visual Studio和GCC。

0 个答案:

没有答案
相关问题