如果我有一个基类,我将其声明为子类,然后添加到由基类组成的向量中,有没有办法将该基类强制转换回子类,因为我知道"基础"其实是孩子?例如:
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?
}
我做错了演员是否是我误解的事情?