弱弱的问下: c++这句怎么不行了,怎么改?

来源:百度知道 编辑:UC知道 时间:2024/05/13 20:01:12
这句 home home1=home("feng",23,65000.0);怎么不行?不能这样用吗?怎么才能用呢?请高手指点!谢谢!

#include<iostream>
using namespace std;

class home
{
private:
char name[30];
int age;
double money;
public:
void input();
void buy(int num,double price);
void show( );
};

void home::buy(int num,double price)
{

cout<<name<<"buy things of "<<num<<"with money"<<num*price<<endl;
}
void home::show( )
{

cout<<name<<'\t'<<age<<'\t'<<money<<endl;
}

int main()
{
home home1=home("feng",23,65000.0);
home1.buy(6,300);
home1.show();
system("pause");
}

#include<iostream>
#include <string.h>
using namespace std;

class home
{
private:
char name[30];
int age;
double money;
public:
home(char *, int ,double); //添加个构造函数
void input();
void buy(int num,double price);
void show( );
};

home::home(char *str, int ag, double mon)//添加个构造函数
{
strcpy(name,str);
age = ag;
money = mon;

}

void home::buy(int num,double price)
{

cout<<name<<"buy things of "<<num<<"with money"<<num*price<<endl;
}
void home::show( )
{

cout<<name<<'\t'<<age<<'\t'<<money<<endl;
}

int main()
{
home home1=home("feng",23,65000.0);
home1.buy(6,300);<