you have to use the concept of base, derive class and use them properly. while doing it, I'm faced with some problems. Can you help me solve the issues ?
My Code :
#include <iostream>
class Base {
public:
Base (int data) : _data(data){}
virtual void printData(){
std::cout << "Base" << _data << std::endl;
}
private:
int _data;
};
class Derived : public Base {
public:
Derived(derivdata) : Base(derivdata){}
void printData(){
cout << "Derived " << _data << endl;
}
}
int main(){
Derived *var = new Derived(5);
var-> printData();
Base *basevar = static_cast<Base>(*var);
basevar-> printData();
}
Aucun commentaire:
Enregistrer un commentaire