标题:private怎么用?
取消只看楼主
lockhawk
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2008-9-17
 问题点数:0 回复次数:1 
private怎么用?
既然不能输入,要来干什么?好象也无法修改吧?
#include <iostream.h>
class yunsuan
{
public:
    int add(int a,int b);
    int cha(int a,int b);
    int ji(int a,int b);
    int shang(int a,int b);
private:
    int a,b;
};
yunsuan::add(int a,int b)
{
    return a+b;
}
yunsuan::cha(int a,int b)
{
    return a-b;
}
yunsuan::ji(int a,int b)
{
    return a*b;
}
yunsuan::shang(int a,int b)
{
    return a/b;
}




int main()
{
    yunsuan temp;
    int a,b;
    int c;
    cout<<"a=";
    cin>>a;
    cout<<"b=";
    cin>>b;
    cout<<"select 1:+;2:-;3:*;4:/;";
    cin>>c;
    switch (c){
    case 1:
        {
            cout<<temp.add(a,b)<<endl;
            break;
        }
    case 2:
        {
            cout<<temp.cha(a,b)<<endl;
            break;
        }
    case 3:
        {
            cout<<temp.ji(a,b)<<endl;
            break;
        }
    case 4:
        {
            if(b==0)cout<<"erreo"<<endl;
        else
            cout<<temp.shang(a,b)<<endl;
        break;
        }
    default:
        cout<<"erreo"<<endl;
    }

return 0;
}
搜索更多相关主题的帖子: private 
2008-11-03 22:21
lockhawk
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2008-9-17
得分:0 
不是啊~主函数里的a和b和private里的a和b不一样吧?
我想改private里的a和b好象也改不了?

人生最大痛苦:虽然不明白你们说什么,但还是要听!
2008-11-03 23:11



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




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

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