| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 358 人关注过本帖
标题:请帮忙解决c++error
只看楼主 加入收藏
晓宁
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2011-9-7
结帖率:71.43%
收藏
已结贴  问题点数:10 回复次数:3 
请帮忙解决c++error
#include<iostream>                       
#include<string>
using namespace std;

class Customer                                            
{
    friend void displayAsFriend(Customer);               
private:
    int custNum;
    double balanceDue;
public:
    Customer(int=0, double=0.0);
    void displayCustomer();
};
Customer :: Customer(int num,double balance)
{
    custNum=num;                                          
    balanceDue=balance;
}
void Customer :: displayCustomer()                  
{
    cout<<"In the member function"<<endl;
    cout<<"Customer #"<<custNum<<" has balance of RM"<<balanceDue<<endl;  
void displayAsFriend(Customer cust)                             
{
    cout<<" In the friend function: "<<endl;
    cout<<" Customer #"<<cust.custNum<<" has a balance of RM "<<cust.balanceDue<<endl;
}

int main()
{
    Customer onePatron(3815,259.25);
    onePatron.displayCustomer();
    displayAsFriend(onePatron);
    return 0;        
}
搜索更多相关主题的帖子: 资金 
2011-09-08 14:43
lqsh
Rank: 2
来 自:山东济南
等 级:论坛游民
帖 子:26
专家分:58
注 册:2011-8-29
收藏
得分:3 
程序代码:
#include<iostream>                     
#include<string>
using namespace std;
class Customer                                          
{
    friend void displayAsFriend(Customer &);  //友元不属于Customer类,不能在它的作用域内定义。            
private:
    int custNum;
    double balanceDue;
public:
    Customer(int num=0, double balance=0.0):custNum(num),balanceDue(balance){
    }
    void displayCustomer();
};
void Customer :: displayCustomer()                
{
    cout<<"In the member function"<<endl;
    cout<<"Customer #"<<custNum<<" has balance of RM"<<balanceDue<<endl;
  
}
void displayAsFriend(Customer &cust)                           
{
    cout<<" In the friend function: "<<endl;
    cout<<" Customer #"<<cust.custNum<<" has a balance of RM "<<cust.balanceDue<<endl;
}
int main()
{
    Customer onePatron(3815,259.25);
    onePatron.displayCustomer();
    displayAsFriend(onePatron);
    return 0;      
} 
  
2011-09-08 15:01
coobae
Rank: 1
等 级:新手上路
帖 子:1
专家分:3
注 册:2011-9-8
收藏
得分:3 
少写了一个括号。。。。。。
2011-09-08 15:03
jcw08120110
Rank: 8Rank: 8
来 自:南京
等 级:蝙蝠侠
帖 子:272
专家分:742
注 册:2009-6-8
收藏
得分:3 
2楼看错了 就是少写了一个括号
程序代码:
void Customer :: displayCustomer()                
{
    cout<<"In the member function"<<endl;
    cout<<"Customer #"<<custNum<<" has balance of RM"<<balanceDue<<endl;
  
}//这里;

君生我未生 我生君以老
2011-09-08 15:17
快速回复:请帮忙解决c++error
数据加载中...
 
   



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

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