1.编译错误stray'\260'in program
1)错:cout<
正:cout<
错:counter--;
2)正:counter--;(符号要用英文的输入法)
正:class B;
Class A
{
public friend class B
};
类定义之前使用要提前声明,否则识别不出来
2.undefined reference to `Count::display_total()'|
原因可能是
1) 就是main.cpp为c++代码,调用了c语言库的函数,因此链接的时候找不到,解
决方法:即在main.cpp中,把与c语言库test.a相关的头文件包含添加一个extern
"C"的声明即可。
2)只声明了函数而未定义函数
3)undefined reference to `Count::counter'|
静态数据成员counter初始化要在类外(最外面)
正:
class Count
{
private:
static int counter;//创建或销毁对象时用静态数据成员counter记录对象数
int obj_id;//给每一个对象提供对象ID号
public:
Count();
static void display_total();
void display();
~Count();
};