こんにちは私は大学での私のコースの仕事に少し問題があります。 私はOrganizationという2つの子クラスと、InsuranceとManufacturemという2つの親クラスを持っています。また、Dequeというコンテナもあります。クラス保険にはstatutory_capital
というフィールドがあります。それはfloat
です。私の仕事は、statutory_capital
を持つorganisation
を表示することです。 Deque.h
だ子クラスの変数へのアクセスをgetterの親クラスで初期化せずに取得する方法
:Organisation.h
だ
#pragma once
#include "Organisation.h"
struct Node
{
Node *Next;
Organisation* data;
};
class Deque
{
public:
void Do_request();
private:
Node *Front;
Node *Back;
};
:ここ
#pragma once
#include <string>
using namespace std;
class Organisation
{
protected:
int workers;
string name;
float experience;
//float statutory_capital; If I uncomment this and get_statutory_capital everything works
public:
Organisation();
Organisation(string Name, float Experience, int Workers);
virtual void show() = 0;
virtual string get_name();
virtual int get_workers();
//virtual float get_statutory_capital();
};
は、ユーザによって書かれたよりも、法定資本金organisations
詳細を見つけるための方法Do_request()
次のとおりです。
void Deque::Do_request()
{
if (Front == NULL)
{
cout << "The deque is empty" << endl;
return;
}
Node *temp = Front;
Insurance tmp;
Insurance *ptr_insurance;
float test_statutory_capital;
cout << "Write the statutory capital to find: ";
cin >> test_statutory_capital;
while (temp != NULL)
{
ptr_insurance = new Insurance(temp->data);
cout << "TESt" << tmp.get_statutory_capital();
if (ptr_insurance != NULL)
{
if (tmp.get_statutory_capital() > test_statutory_capital)
{
cout << "Insurance with capital more than test: "<< temp->data->get_name() << "\n";
}
}
temp = temp->Next;
}
}
は、私は何をすべきを追加しないでください変数statutory_capital
私の親にclass
組織、私はここでそれを必要としない、私のクラスの原因製造業は法定資本を持っていません。ありがとう!
代わりに[mcve]が表示されますか? – IInspectable
Organizationには、0を返す関数しか必要ありません。変数を返す関数でInstitutionをオーバーライドすることができます。 –
はい、30分で追加します – Mark