Przy założeniu, ze kod wygląda tak:
#include <iostream>
#include <string>
using namespace std;
class Bazowa {
private:
string x;
public:
Bazowa ();
Bazowa (string x):
x(x)
{}
string getX() const { return x;}
void setX(string x) {this->x=x;}
};
class Pochodna :public Bazowa{
private:
string y;
public:
Pochodna();
Pochodna(string x, string y):
Bazowa(x),
y(y)
{}
string getY() const { return x;}
void setY(string x) {this->x=x;}
};
int main(){
Bazowa **tab = new Bazowa*[1]
tab[0] = new Pochodna ("x","y")
tab[0]->setY("new Y"); // [ERROR] 'class Bazowa' has no member named 'setY'
return 0;
}
Czy w takim wypadku jest sposób aby zmienić wartość klasy pochodnej, chociaż tablica jest obiektów klasy bazowej?