我正在尝试将 std::shared_ptr
静态转换为其基类。给定类:
class ImportFileSetting {};
class ImportFileSettingSelect:ImportFileSetting {}
我尝试了以下代码:
std::shared_ptr<ImportFileSettingSelect> selectedSheet_ = std::make_shared<ImportFileSettingSelect>();
std::vector<std::shared_ptr<ImportFileSetting>> settings_;
settings_.push_back(static_pointer_cast<ImportFileSetting>(selectedSheet_));
我根据cppreference.com找到的.但它无法编译:
5>src\TechAdminServices\database\techCore\processes\ImportDataSourceExcel.cpp(32): error C2065: 'static_pointer_cast' : undeclared identifier
5>src\TechAdminServices\database\techCore\processes\ImportDataSourceExcel.cpp(32): error C2275: 'ImportFileSetting' : illegal use of this type as an expression
5> d:\techsys\techadmin\techadminservices\src\techadminservices\database\techcore\processes\ImportFileSetting.h(7) : see declaration of 'ImportFileSetting'
我该如何解决这个问题?
最佳答案
您缺少命名空间:
settings_.push_back(std::static_pointer_cast<ImportFileSetting>(selectedSheet_));
// ^^^^^
关于c++ - 错误 C2065 : 'static_pointer_cast' : undeclared identifier - Visual Studio 2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36426386/