标题:菜鸟问问题 关于类的问题
取消只看楼主
tfg0116
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2008-10-9
 问题点数:0 回复次数:1 
菜鸟问问题 关于类的问题
我自己写了一个类,存类的头文件名为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]]
搜索更多相关主题的帖子: private include 源代码 public called 
2008-10-30 20:42
tfg0116
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2008-10-9
得分:0 
guojianxun谢谢
2008-11-02 20:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-241568-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.268705 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved