###前提・実現したいこと
実行結果は
AIFLの貸出高は2000億円
TADANOの建造物はcrane
とならなければいけません
条件としてmain関数はこのままです。
###発生している問題・エラーメッセージ
string getName()const{ return name; }で
nameを返したいのですがnameがprivateの為アクセス出来ません
どうすればnameはprivateのままでアクセス出来ますか?
###ソースコード
lang
1#include <iostream> 2#include <string> //文字列操作用クラス 3using namespace std; 4 5//会社クラス定義 6class Company { 7 string name; //会社名 8public: 9 Company(string cname = "") : name(cname){} 10 11}; 12//金融業クラス定義 13class Finance : public Company { 14 int loan; //貸出高(億円) 15public: 16 Finance(string fname, int floan) : Company(fname),loan(floan){} 17 int getLoan() { return loan; } 18 string getName()const{ return name; } 19}; 20///////////////////////////////////////////////////// 21//製造業クラス定義 22class Production : public Company { 23 string product; //製造物 24public: 25 Production(string pname, string pproduct) : Company(pname),product(pproduct){} 26 string getProduct()const{ return product; } 27 string getName()const{ return name; } 28}; 29///////////////////////////////////////////////////// 30int main() 31{ 32 Finance* financeP(new Finance("AIFL", 2000)); 33 Production* productionP(new Production("TADANO", "crane")); 34 35 cout << financeP->getName() << "の貸出高は" 36 << financeP->getLoan() << "億円" << endl; 37 cout << productionP->getName() << "の製造物は" 38 << productionP->getProduct() << endl; 39 40 delete financeP; 41 delete productionP; 42 return 0; 43}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。