2016-04-05 113 views
0

我正在嘗試將std::shared_ptr靜態投射到其基類。鑑於類:錯誤C2065:'static_pointer_cast':未聲明的標識符 - Visual Studio 2010

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' 

我該如何解決這個問題?

回答

1

你缺少的命名空間:

settings_.push_back(std::static_pointer_cast<ImportFileSetting>(selectedSheet_)); 
//     ^^^^^ 
相關問題