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

刚学C++,关于类的问题

killer_l 发布于 2007-06-08 19:28, 397 次点击

写了个两个数求和的程序,不知道哪错了.....

he.h文件

class He
{
private:
    int a;
    int b;
public:
    void setHe(int,int);
    int geta();
    int getb();
    He getHe();
    int add();
}


/***********************************************************************************************/

he.cpp文件
程序代码:


#include <iostream.h>
#include \"he.h\"


void He::setHe(int c,int d)
{
    a = c;
    b = d;
}



int He::geta()
{
    return a;
}


int He::getb()
{
    return b;
}


He He::getHe()
{
    return *this;
}


int He::add()
{
    return a + b;
}



/***********************************************************************************************/
main.cpp文件


#include <iostream.h>
#include \"he.h\"



int main()
{
    He s;
    s.setHe(20,30);
    cout << s.geta() << \"+\" << s.getb() << \"=\" << s.add() << \"\n\";
}


4 回复
#2
aipb20072007-06-08 21:27
类定义后没加分号。
#3
SamuelMe2007-06-09 00:27

class He

{

............

};

#4
killer_l2007-06-09 07:42
晕了,这么简单的错误谢谢......
#5
yuyunliuhen2007-06-09 12:32
^_^ 以后注意就OK了

1