![]() |
#2
hoho5682011-09-08 00:43
![]() #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); //函数没有返回值。 } 真心乱,都是基本错误。 |
#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);
}