속성을 부여하고 난 FlowersGarden의 수는 종 내 목록에 장미 개체를 계산하려면 :계수 요소 그래서 나는이 두 개의 클래스를 가지고
class Garden {
private:
string owner;
double lenght, width;
public:
Garden(string ow, double l, double w) {
this->ownder = ow;
this->lenght = l;
this->width = w;
}
class FlowersGarden: public Garden {
private:
string species;
public:
FlowersGarden(string ow, double l, double w, string sp):Garden(ow, l, w) {
this->species = sp;
}
string GetSpecies()const {return species;};
};
MAIN.CPP
Graden** list;
list = new Garden* [5];
list[0] = new Garden("asdas", 54, 57);
list[1] = new FlowersGarden("tyyty", 98, 87, "rose");
list[2] = new FlowersGarden("asdasd", 578, 212, "sadas");
list[3] = new Garden("uyiyui", 687, 212);
int count = 0;
for (int i = 0; i < 4; i++)
if(dynamic_cast<FlowersGarden*>(list[i]))
if(list[i]->GetSpecies() == "rose")
count++;
그게 내가이 문제를 해결할 수 있다고 생각하는데 나는이 오류가 발생합니다. "class 'Garden'에는 'GetSpecies'라는 멤버가 없습니다. 이유는 알지만 다른 방법은 모르겠습니다.
C에 대한 귀하의 사용 C#을 문법 ++는 것 같다. –
대신에'GetSpecies()'GetSpecie()' – max66
그건 오타 였지만 그게 문제의 원인이 아니 었습니다. – SuperChit