未定义std共享\u指针\u转换 我正在尝试在Apache箭头C++中记录的示例示例。 该示例使用共享的定点强制转换,如下所示(代码段)
版本未定义std共享\u指针\u转换 我正在尝试在Apache箭头C++中记录的示例示例。 该示例使用共享的定点强制转换,如下所示(代码段),c++,c++11,shared-ptr,C++,C++11,Shared Ptr,版本 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 PURPO
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;
}
错误
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);
example.cpp:在函数“int main()”中:
示例.cpp:24:44:错误:“共享指针\u cast”不是“std”的成员
std::shared\u ptr int64\u array=std::shared\u pointer\u cast(数组);
^
示例.cpp:24:79:错误:在“>”标记之前应该有主表达式
std::shared\u ptr int64\u array=std::shared\u pointer\u cast(数组);
我没有看到任何关于std::shared\u pointer\u cast
问题
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.
您应该根据您的意图使用
静态\u指针\u投射
或动态\u指针\u投射
下面是C++ 11中支持的所有强制转换:
但是,在C++11中没有所谓的std::shared\u pointer\u cast
另外,它应该适合你。尝试static\u cast
而不是std::shared\u pointer\u cast
<强>使用强制转换时要考虑的要点:强>
static\u cast
不执行运行时检查。如果您知道您引用的是特定类型的对象,那么应该使用此选项,因此不需要进行检查。它还用于避免隐式转换,而不是显式转换
dynamic\u cast
用于不知道对象的动态类型的情况。如果向下转换并且参数类型不是多态的,则不能使用动态_cast。例如:
Regular cast
是一种C风格的cast,它结合了所有的const\u cast
、static\u cast
和reinterpret\u cast
,但也不安全
查看更多关于C++中的转换的用法。
这个例子可能意味着@宋元耀:引用的链接没有引用SyrdPoPiType Cask。请注意,该示例没有引用静态指针转换。@kumar\u m\u kiran没有std::shared\u pointer\u cast
;这个例子是错误的。。?或者它只是一个抽象的措辞,包括std::static\u pointer\u cast
,std::dynamic\u pointer\u cast
,std::const\u pointer\u cast
,std::reinterpret\u pointer\u cast
。