| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 467 人关注过本帖
标题:类类型定义。。。做了个类类型的小程序,不知道错哪里请大家帮我看看
只看楼主 加入收藏
a632034079
Rank: 2
等 级:论坛游民
帖 子:115
专家分:34
注 册:2009-10-3
结帖率:86.11%
收藏
已结贴  问题点数:5 回复次数:2 
类类型定义。。。做了个类类型的小程序,不知道错哪里请大家帮我看看
看例题做的。。。还不是很明白类类型的意思。。。做了个程序错误很多,自己能改的,都改过来了。。。还是错了不少....大侠帮我看看先谢过了。错误报告在下面....
#include <iostream>
#include <string>
using namespace std;
class studentClass
{
private:
    string strName;
    string strClass;
    int number;
    string homeAddress;
    int chinese;
    int math;
    int english;
public:
    string getstrName(){return strName;};
    string gethomeAddress(){return homeAddress;};
};
int main()
{
    studentClass student[30];
    student[0].strName="LIUCE";
    student[0].strClass="Class 2";
    student[0].number=12366;
    student[0].homeAddress="HuangYan road";
    student[0].chinese =100;
    student[0].math =100;
    student[0].english =100;
    cout<<student[0].strName
        <<"live in"
        <<student[0].homeAddress
        <<".His nuber is"
        <<student[0].number<<endl;
    cin.get();
    return 0;
}


错误报告;
Compiling...
jhg.cpp
E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(21) : error C2248: 'strName' : cannot access private member declared in class 'studentClass'
        E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(7) : see declaration of 'strName'
E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(22) : error C2248: 'strClass' : cannot access private member declared in class 'studentClass'
        E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(8) : see declaration of 'strClass'
E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(23) : error C2248: 'number' : cannot access private member declared in class 'studentClass'
        E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(9) : see declaration of 'number'
E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(24) : error C2248: 'homeAddress' : cannot access private member declared in class 'studentClass'
        E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(10) : see declaration of 'homeAddress'
E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(25) : error C2248: 'chinese' : cannot access private member declared in class 'studentClass'
        E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(11) : see declaration of 'chinese'
E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(26) : error C2248: 'math' : cannot access private member declared in class 'studentClass'
        E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(12) : see declaration of 'math'
E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(27) : error C2248: 'english' : cannot access private member declared in class 'studentClass'
        E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(13) : see declaration of 'english'
E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(29) : error C2248: 'strName' : cannot access private member declared in class 'studentClass'
        E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(7) : see declaration of 'strName'
E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(31) : error C2248: 'homeAddress' : cannot access private member declared in class 'studentClass'
        E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(10) : see declaration of 'homeAddress'
E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(32) : error C2248: 'number' : cannot access private member declared in class 'studentClass'
        E:\C++\MSDev98\MyProjects\dfvg\jhg.cpp(9) : see declaration of 'number'
执行 cl.exe 时出错.

dfvg.exe - 1 error(s), 0 warning(s)
我郁闷错了那么多..............
搜索更多相关主题的帖子: 定义 个类 类型 
2009-10-06 16:36
flyingcloude
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:6
帖 子:598
专家分:1512
注 册:2008-1-13
收藏
得分:5 
private:
    string strName;
    string strClass;
    int number;
    string homeAddress;
    int chinese;
    int math;
    int english;
你这些都是private啊,只有类本省的方法才能访问到,在main函数中是访问不到的啊,所以就会报错了
要么把private改成public

你能学会你想学会的任何东西,这不是你能不能学会的问题,而是你想不想学的问题
2009-10-06 16:54
a632034079
Rank: 2
等 级:论坛游民
帖 子:115
专家分:34
注 册:2009-10-3
收藏
得分:0 
.................没人会吗???
2009-10-06 20:25
快速回复:类类型定义。。。做了个类类型的小程序,不知道错哪里请大家帮我看看
数据加载中...
 
   



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

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