struct Foo{
Foo(int val) : i(val){}
Foo &operator=(const Foo&){ //... }
void fun(){}
int i;
std::string s;
};
struct Bar : public Foo{
Bar(int i) : Foo(i){}
Bar &operator=(const Bar &other){
this->Foo::operator=(other);
return *this;
}
void new_func(){}
}
Take this piece of code for example, Bar is extended version of Foo, and no additional member variables are added. Any danger downcasting a Foo instance to Bar, and use the extended function?
Also, is there a way to allow me downcast Foo to Bar implicitly, so I don't have to write static_cast all the time?