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

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=0;
    balanceDue=0.0;
}
void Customer :: displayCustomer()
{
    cout<<"In the member function"<<endl;
    cout<<"Customer #"<<custNum<<" has balance of RM"<<cust.custNum<<endl;
}
void Customer :: 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);
    Customer.display.Customer();
    displayAsFriend(onePatron);
}
搜索更多相关主题的帖子: void double function private balance 
2011-09-07 21:18
hoho568
Rank: 5Rank: 5
等 级:职业侠客
帖 子:101
专家分:378
注 册:2009-7-14
收藏
得分:0 
程序代码:
#include<iostream.h>                                  //没有这个头文件,错!改为#include<iostream>
#include<string.h>

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=0;                                       //这里虽然没有错误,但是这个构造函数真心没用啊。。形参一点作用没有。。
    balanceDue=0.0;
}
void Customer :: displayCustomer()
{
    cout<<"In the member function"<<endl;                                     //cout没有命名空间,在前面#include之后,加上标准命名空间using namespace std; 
    cout<<"Customer #"<<custNum<<" has balance of RM"<<cust.custNum<<endl;    //这个cust是什么东西,突然跑出来的一个对象?不明白。
}
void Customer :: 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);           //声明类的对象时,怎么会有符号呢,去掉.
    Customer.display.Customer();               //这是什么东西啊。。是不是onePatron.displayCustomer();?
    displayAsFriend(onePatron);                //函数没有返回值。
}



真心乱,都是基本错误。
2011-09-08 00:43
yiwenfei
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-9-4
收藏
得分:0 
楼主错误太多了,基本的格式都没懂。
#include<iostream.h>                        //这里VC6.0是支持的,05以后的版本不支持,按楼上的说法
#include<string.h>

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;                                                                     //定义了返回值类型就要返回,不然有warning
}
2011-09-08 10:42
快速回复:求C++编程帮忙解决error
数据加载中...
 
   



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

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