[問題]怎麼叫出物件內的一些參數?
我寫的以下程式碼有一些問題:
#include<iostream>
using namespace std;
class BankAccount
{
public:
BankAccount(int, double, double);
private:
int x;
double y;
double z;
};
BankAccount::BankAccount(int x=0,double y=0,double z=0)
{
this->x = x;
this->y = y;
this->z = z;
}
class Portfolio : public BankAccount
{
public:
Portfolio(int,int,double,int,double,double);
};
Portfolio::Portfolio(int A=0,int B=0,double C=0,int D=0,double E=0,double F=0)
: BankAccount( B, C)
{
cout<< B << "and"<< C <<endl;
}
Portfolio::Portfolio(int A=0,int B=0,double C=0,int D=0,double E=0,double F=0)
: BankAccount(D,E,F)
{
cout<< D << "and"<< E << "and" << F <<endl;
}
int main(){
BankAccount account(1234, 10000, 0.03);
Portfolio portfolio(5555, 4321, 30000, 789, 10000, 0.03);
system("pause");
return 0;
}
在第二個class(叫做portfolio)中,我有成功叫出B和C兩個參數,但是想叫第二次別的參數
時(我想再叫出D和E和F),卻發現不行了,它說我redefinition of
`Portfolio::Portfolio(int, int, double, int, double, double)'
好像是重複定義了的樣子,如果比照叫出B和C的方式的話,有什麼方法可以成功叫出兩次參
數呢?
謝謝~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.62.52
→
06/19 12:54, , 1F
06/19 12:54, 1F
→
06/19 13:04, , 2F
06/19 13:04, 2F
→
06/19 14:27, , 3F
06/19 14:27, 3F
推
06/19 15:21, , 4F
06/19 15:21, 4F
→
06/19 15:35, , 5F
06/19 15:35, 5F