性病shared_pointer_cast未定义
std shared_pointer_cast not defined
我正在尝试一个在 apache 箭头C++示例中记下的示例示例。 该示例使用共享点转换,如下所示(代码片段)
版本
g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3aka8.0.2) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
法典
int main()
{
Int64Builder builder(arrow::default_memory_pool(), arrow::int64());
builder.Append(8);
std::shared_ptr<Array> array;
builder.Finish(&array);
std::shared_ptr<Int64Array> int64_array = std::shared_pointer_cast<Int64Array>(array);
return 0;
}
编译标志
但是,当我使用以下标志编译代码时,出现未定义的错误。
g++ example.cpp -O2 -std=c++11 -I/workspace/arrow/arrow-master/cpp/src -L/workspace/arrow/arrow-master/cpp/release/release -larrow -larrow_jemalloc
错误
example.cpp: In function 'int main()':
example.cpp:24:44: error: 'shared_pointer_cast' is not a member of 'std'
std::shared_ptr<Int64Array> int64_array = std::shared_pointer_cast<Int64Array>(array);
^
example.cpp:24:79: error: expected primary-expression before '>' token
std::shared_ptr<Int64Array> int64_array = std::shared_pointer_cast<Int64Array>(array);
我没有看到任何std::shared_pointer_cast
的文档
问题
- 我错过了什么,这是 c++11 版本中的可编译代码吗?
- C++11 版本中的替代方案是什么?
您应该根据您的意图使用static_pointer_cast
或dynamic_pointer_cast
。
以下是 C++ 11 中支持的所有转换:
http://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast
但是,在 C++11 中没有什么叫做std::shared_pointer_cast
此外,static_cast应该适合您。尝试static_cast
而不是std::shared_pointer_cast
使用强制转换时要考虑的要点:
static_cast
不执行运行时检查。如果您知道引用特定类型的对象,则应使用此方法,因此不需要检查。它也用于避免隐式转换,而是使其明确
dynamic_cast
用于您不知道对象的动态类型的情况。如果向下转换并且参数类型不是多态的,则不能使用dynamic_cast。举个例子:
Regular cast
是一个C式演员阵容,结合了所有的const_cast
、static_cast
和reinterpret_cast
,但它也是不安全的。
查看此答案以了解有关C++中使用的铸件的更多信息。
相关文章:
- 编译C++时未定义的引用
- vscode g++链路故障:体系结构x86_64的未定义符号
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 不知道某个东西是否被忽略会引入未定义的行为吗
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- c++11评估顺序(未定义的行为)
- 使用mysql c++连接器的未定义引用
- 从python调用openMP共享库时,未定义opnMP函数
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号
- Cmake 链接问题:未定义对 Button::mousePressEvent(QGraphicsSceneMouseE
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 具有外部"c"和程序集的未定义函数
- 此增量后语句是否会导致未定义的行为?
- 尝试调用 .h 文件中定义的变量时出现变量未定义错误
- 在C++中使用内联方法时出现未定义的符号错误
- 对 Scalar ::Scalar() 的未定义引用