注册 登录
编程论坛 C++教室

菜鸟问问题 关于类的问题

tfg0116 发布于 2008-10-30 20:42, 937 次点击
我自己写了一个类,存类的头文件名为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]]
8 回复
#2
wangluxi2008-10-30 20:45
exam.h中class Domo
应改为class demo
再编译一下
#3
soar20082008-10-30 23:39
Demo b();中的括号去掉
#4
asd67918682008-10-31 08:32
Demo()
        {
            cout<<"Demo() is called!"<<endl;
        }
你这个是什么
析构函数那???
还是拷贝函数???
没看懂
#5
danielxu2008-10-31 08:46
类名错了。。。。Demo()
        {
            cout<<"Demo() is called!"<<endl;
        }
默认呢构造函数。。。
#6
guojianxun2008-10-31 23:31
先是Domo,然后成了Demo,当然不可以了。
马虎,这种问题慢慢会好的。
#7
lovely061232008-11-02 19:08
是想实现重载涵数吗?
是想实现重载涵数吗?
#8
冰烨2008-11-02 19:15
呵呵,有点眼花,应该是手误的问题吧
#9
tfg01162008-11-02 20:00
guojianxun谢谢
1