麻烦各位前辈替我看看这个类错在哪里?
麻烦各位前辈替我看看这个类错在哪里?
#ifdef A_H_
#define A_H_
#include <iostream>
using namespace std;
class A
{
public:
A(int a);
static void print();//静态成员函数
private:
static int aa;//静态数据成员的声明
static const int count;//常量静态数据成员(可以在构造函数中初始化)
const int bb;//常量数据成员
};
int A::aa=0;//静态成员的定义+初始化
const int A::count=25;//静态常量成员定义+初始化
A::A(int a):bb(a)//常量成员的初始化
{
aa+=1;
}
void A::print()
{
cout<<"count="<<count<<endl;
cout<<"aa="<<aa<<endl;
}
#endif
void main()
{
A a(10);
A::print();//通过类访问静态成员函数
a.print();//通过对象访问静态成员函数
}
以下是错误提示:
F:\code\First_C++_Book\const_static_p\const_static_p.cpp(13) : error C2065: 'A' : undeclared identifier
F:\code\First_C++_Book\const_static_p\const_static_p.cpp(13) : error C2146: syntax error : missing ';' before identifier 'a'
F:\code\First_C++_Book\const_static_p\const_static_p.cpp(13) : error C2065: 'a' : undeclared identifier
F:\code\First_C++_Book\const_static_p\const_static_p.cpp(14) : error C2653: 'A' : is not a class or namespace name
F:\code\First_C++_Book\const_static_p\const_static_p.cpp(14) : error C2065: 'print' : undeclared identifier
F:\code\First_C++_Book\const_static_p\const_static_p.cpp(15) : error C2228: left of '.print' must have class/struct/union type
[解决办法]
#ifndef