c++ - 错误 C2065 : 'static_pointer_cast' : undeclared identifier - Visual Studio 2010

标签 c++ visual-studio-2010 c++11

我正在尝试将 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/

相关文章:

visual-studio-2010 - 从命令行运行 mstest.exe 时没有调试跟踪

c# - 连接后如何测试TCPClient连接断开?

c++ - 为什么通过 const 引用传递 constexpr 对象有效,但按值不编译

c++ - 使用 std::enable_if 时如何拆分声明和实现

C++11 future.wait_for() 总是返回 future_status::timeout

c++ - 可变参数的 value_type

c++ - 使用基于范围的 for 循环取消引用 vector 指针

c++ - C++程序中如何按字母顺序排序

C++ UDP 在一个类中接收一个 vector

c++ - 确定程序本身是否对文件具有一定访问权限的最简洁方法是什么?