const限定符的问题
a.h内容如下:
class A
{
public:
int testA();
};
b.h内容如下:
class A;
class B
{
public:
int testB(const A &a);
};
b.cpp内容如下:
#include "a.h"
#include "b.h"
int B::testB(const A &a)
{
a.testA();
return 0;
}
g++ -c b.cpp出现如下错误:
b.cpp: In member function ‘int B::testB(const A&)’:
b.cpp:6: 错误: 将‘const A’作为‘int A::testA()’的‘this’实参时丢弃了类型限定
请问为什么会出现这个错误?我用const A &a这个作型参不行吗?(把const去掉就可以编译通过)