#include <iostream>
#include <string>
#include <typeinfo.h>
#include <vector>
class OS{
protected :
std::string label;
public :
OS(std::string label):label(label){}
virtual OS& operator = (const OS& os) {
label = os.label;
return *this;
}
virtual void show(std::ostream &) const = 0;
};
class Window : public OS {
public :
Window(std::string wLabel):OS(wLabel){}
virtual Window& operator = (OS* ptr)
{
if(dynamic_cast<Window*>(ptr) != 0)
return *this;
else{
dynamic_cast<OS* >(ptr);
return *this;
}
}
virtual void show(std::ostream &os) const{
os << "OS : " << label << '\n';
}
};
class Linux : public OS {
public :
Linux(std::string wLabel):OS(wLabel){}
virtual Linux& operator = (OS* ptr)
{
if(dynamic_cast<Linux*>(ptr) != 0)
return *this;
else{
dynamic_cast<OS* >(ptr);
return *this;
}
}
virtual void show(std::ostream &os) const{
os << "OS : " << label << '\n';
}
};
void showAll(std::vector<OS* > &operating_system)
{
for(std::vector<OS* >::const_iterator iss = operating_system.begin();
iss != operating_system.end(); ++iss)
{
}
}
int main()
{
std::vector<OS* > operating_system;
operating_system.push_back(new Window("Vista"));
operating_system.push_back(new Window("XP"));
operating_system.push_back(new Window("Window98"));
operating_system.push_back(new Linux("Unbutu"));
operating_system.push_back(new Linux("Fedora"));
operating_system.push_back(new Linux("RedHat"));
showAll(operating_system);
std
::cout << "Hack product !!!^_^ \n\n";
//Wow Vista đã biến thành RedHat, what the hack T_T!
operating_system[0] = operating_system[5];
showAll(operating_system);
for(int x = 0; x < operating_system.size(); ++x){
std
::cout << "Deleting : \n " << typeid(*operating_system
[x
]).
name() << '\n'; }
return 0;
}