| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 802 人关注过本帖
标题:C++刚刚看到类 照着书里的程序写了一遍 不知道怎么有错误。
只看楼主 加入收藏
一只失语的猫
Rank: 2
等 级:论坛游民
帖 子:35
专家分:14
注 册:2011-10-26
结帖率:88.89%
收藏
已结贴  问题点数:10 回复次数:3 
C++刚刚看到类 照着书里的程序写了一遍 不知道怎么有错误。
求大虾们解释一下。 那里出错了。

//Studenr61_1.h
#include<iostream.h>
#include<string.h>

class student
{
private:
    unsigned int code;
    string name;
public:
    void SetCode(unsigned int code)
    {
        this->code=code;
    }
    int GetCode()
    {
        return code;
    }
    void SetName(string  name)
    {
        this->name=name;
    }
    string GetName()
    {
        return name;
    }
    void shoe();
};
void Students::show()
{
    cout<<"编号:"<<code<<"\t"<<"姓名"<<name<<"\t";
}



--------------------Configuration: jj - Win32 Debug--------------------
Compiling...
jj.cpp
C:\Documents and Settings\Administrator\桌面\编程文件存档\jj.cpp(9) : error C2146: syntax error : missing ';' before identifier 'name'
C:\Documents and Settings\Administrator\桌面\编程文件存档\jj.cpp(9) : error C2501: 'string' : missing storage-class or type specifiers
C:\Documents and Settings\Administrator\桌面\编程文件存档\jj.cpp(9) : error C2501: 'name' : missing storage-class or type specifiers
C:\Documents and Settings\Administrator\桌面\编程文件存档\jj.cpp(11) : error C2059: syntax error : 'constant'
C:\Documents and Settings\Administrator\桌面\编程文件存档\jj.cpp(19) : error C2061: syntax error : identifier 'string'
C:\Documents and Settings\Administrator\桌面\编程文件存档\jj.cpp(23) : error C2146: syntax error : missing ';' before identifier 'GetName'
C:\Documents and Settings\Administrator\桌面\编程文件存档\jj.cpp(23) : error C2501: 'string' : missing storage-class or type specifiers
C:\Documents and Settings\Administrator\桌面\编程文件存档\jj.cpp(26) : warning C4183: 'GetName': member function definition looks like a ctor, but name does not match enclosing class
C:\Documents and Settings\Administrator\桌面\编程文件存档\jj.cpp(29) : error C2653: 'Students' : is not a class or namespace name
C:\Documents and Settings\Administrator\桌面\编程文件存档\jj.cpp(31) : error C2065: 'code' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\编程文件存档\jj.cpp(31) : error C2065: 'name' : undeclared identifier
执行 cl.exe 时出错.

jj.obj - 1 error(s), 0 warning(s)


急。。。。
搜索更多相关主题的帖子: class private include public 
2011-12-07 14:32
一只失语的猫
Rank: 2
等 级:论坛游民
帖 子:35
专家分:14
注 册:2011-10-26
收藏
得分:0 
   void shoe();
};
void Students::show()
{
    cout<<"编号:"<<code<<"\t"<<"姓名"<<name<<"\t";
}

  这里的show改过了还是错。
2011-12-07 14:34
cosam
Rank: 4
等 级:业余侠客
帖 子:146
专家分:259
注 册:2011-8-25
收藏
得分:10 
我用vs2008。
程序代码:
#include<iostream>
#include<string>

class student
{
private:
    unsigned int code;
    std::string name;
public:
    void SetCode(unsigned int code)
    {
        this->code=code;
    }
    int GetCode()
    {
        return code;
    }
    void SetName(std::string name)
    {
        this->name=name;
    }
    std::string GetName()
    {
        return name;
    }
    void show();
};
void student::show()//student跟类名一样,不要大写了
{
    std::cout<<"编号:"<<code<<"\t"<<"姓名"<<name<<"\t";
}
int main()//写上入口函数吧
{
    return 0;
}

 
2011-12-07 15:29
jj7412530
Rank: 2
等 级:论坛游民
帖 子:19
专家分:40
注 册:2011-9-20
收藏
得分:0 
类名是student    为什么在类外写成员函数体的时候却是students呢
2011-12-08 00:37
快速回复:C++刚刚看到类 照着书里的程序写了一遍 不知道怎么有错误。
数据加载中...
 
   



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

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