c++外部类中在构造函数时如何给内部类属性赋值?
#include<iostream.h>#include<string.h>classMoney{private:floatammount;public:Money(fl...
#include<iostream.h>
#include<string.h>
class Money
{
private:
float ammount;
public:
Money(float a=0): amount(a)
{}
};
class Account
{
private:
long accountNo;
char name[30];
Money remains;
public:
Account(long a=0,char *n==NULL,Money m):
account(a),remains(m)
{
strcpy(name,n);
}
};
如何在class Account 的构造函数中给 remains 赋初值??? 展开
#include<string.h>
class Money
{
private:
float ammount;
public:
Money(float a=0): amount(a)
{}
};
class Account
{
private:
long accountNo;
char name[30];
Money remains;
public:
Account(long a=0,char *n==NULL,Money m):
account(a),remains(m)
{
strcpy(name,n);
}
};
如何在class Account 的构造函数中给 remains 赋初值??? 展开
3个回答
展开全部
#include<iostream.h>
#include<string.h>
class Money
{
private:
float amount;
public:
Money(Money &m){ this->amount = m.amount ;}
Money(float a=0): amount(a){}
};
class Account
{
private:
long accountNo;
char name[30];
Money remains;
public:
Account(long a=0,char *n=NULL,Money m):accountNo(a),remains(m){
strcpy(name,n);
}
};
加个拷贝构造函数给Money
#include<string.h>
class Money
{
private:
float amount;
public:
Money(Money &m){ this->amount = m.amount ;}
Money(float a=0): amount(a){}
};
class Account
{
private:
long accountNo;
char name[30];
Money remains;
public:
Account(long a=0,char *n=NULL,Money m):accountNo(a),remains(m){
strcpy(name,n);
}
};
加个拷贝构造函数给Money
展开全部
你写对了啊,就是这样写,
Account(long a=0,char *n==NULL,Money m): account(a),remains(m)
{
strcpy(name,n);
}
Account(long a=0,char *n==NULL,Money m): account(a),remains(m)
{
strcpy(name,n);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你自己已经写出来了,还问什么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询