菜鸟问问题 关于类的问题
我自己写了一个类,存类的头文件名为exam,然后生成的名字是exam.h下面是头文件的源代码:
#ifndef EXAM_H
#define EXAM_H
#include<iostream>
using namespace std;
class Domo
{
public:
Demo(int a, int b)
{
x = a;
y = b;
cout<<"Demo(int, int) is called!"<<endl;
}
Demo()
{
cout<<"Demo() is called!"<<endl;
}
void show()
{
cout<<"x= "<<x<<" y= "<<y<<endl;
}
private:
int x;
int y;
};
#endif
然后我在同一工程下new了一个源文件,原程序为:
#include "exam.h"
#include<iostream>
using namespace std;
int main()
{
Demo a(3, 5);
a.show();
Demo b;
b.show();
return 0;
}
编译后有错,下面是出错提示:请高手指点
MSDev98\MyProjects\Demo_h\exam_1.cpp(7) : error C2065: 'Demo' : undeclared identifier
D:\vc++\MSDev98\MyProjects\Demo_h\exam_1.cpp(7) : error C2146: syntax error : missing ';' before identifier 'a'
D:\vc++\MSDev98\MyProjects\Demo_h\exam_1.cpp(7) : error C2065: 'a' : undeclared identifier
D:\vc++\MSDev98\MyProjects\Demo_h\exam_1.cpp(8) : error C2228: left of '.show' must have class/struct/union type
D:\vc++\MSDev98\MyProjects\Demo_h\exam_1.cpp(9) : error C2146: syntax error : missing ';' before identifier 'b'
D:\vc++\MSDev98\MyProjects\Demo_h\exam_1.cpp(9) : error C2065: 'b' : undeclared identifier
D:\vc++\MSDev98\MyProjects\Demo_h\exam_1.cpp(10) : error C2228: left of '.show' must have class/struct/union type
Error executing cl.exe.
exam_1.obj - 7 error(s), 0 warning(s)
[[it] 本帖最后由 tfg0116 于 2008-10-31 08:48 编辑 [/it]]