If I have a base class that I declared it as a child class, and then added to a vector consisting of the base class, is there a way to cast that base class back to a child class, since I know that the "base" is in fact the child? For example:
class Libitem{
//......
};
class Book : public Libitem{
//......
}
int main{
vector<Libitem> lib;
Libitem book = Book();
lib.push_back(book);
Book b = static_cast<Book>(lib.at(0)); //this is wrong. Is there a way to do this correctly?
}
Am I doing my cast wrong or is their something that I'm misunderstanding?