unique_ptr没有成员函数
unique_ptr has no member function
我正在将我的 gcc 4.4 更新到 gCC 4.7,我将这样做以使用 4.7。
我的问题是当我使用unique_ptr
时。我写了这段代码
#include <iostream>
#include <memory>
#include <CL/cl.h>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
std::unique_ptr<cl_platform_id[]>yt;
yt = std::unique_ptr<icl_platform_id[]> (new cl_platform_id [3]);
/* yt.get()[0] = ...... */ this is error no member found
return 0;
}
但是我想使用yt
成员,例如uique_ptr::get()
,而我得到的唯一功能是operator*
,那么问题是什么?
编辑:
这是我的问题:http://image-load.biz/?di=6FBY
这将是 IDE 成员建议的问题。 std::unique_ptr
当然有一个成员pointer get() const noexcept;
,在默认模板和数组的部分专用化中。
如果您自己键入get()
,那么编译器应该很高兴。不幸的是,我从未使用过该IDE,因此我无法帮助您修复其自动完成器。
是否应该调用get()
是另一个问题;您可以像yt[0]
访问数组元素等。 get()
仅适用于实际需要原始指针的极少数情况。
你想要这样的东西:
std::unique_ptr<cl_platform_id[]> yt ( new cl_platform_id[3] );
yt[0].some_member();
相关文章:
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 将公共但非静态的成员函数与ALGLIB集成
- 使用指向成员的指针将成员函数作为参数传递
- 将重载的成员函数传递给函数模板
- 我不小心调用了一个没有自己类对象的成员函数.但这是怎么回事呢
- 如何在C++中使用非静态成员函数作为回调函数
- C++错误C2600:无法定义编译器生成的特殊成员函数(必须首先在类中声明)
- 关联容器的下界复杂性:成员函数与非成员函数
- 在 C++ 中用派生类型重写成员函数
- 链表的泛型函数remove()与成员函数remove)
- 如何将lambda作为模板类的成员函数参数
- constexpr构造函数需要常量成员函数时出现问题
- 将自由函数绑定为类成员函数
- 区分非成员函数和头文件中的成员函数
- 如何从子成员函数修改父公共成员变量
- 保留对其他类的成员函数的引用
- 在运算符重载定义中使用成员函数(const错误)
- 内联如何影响模块接口中的成员函数
- 将成员函数指针作为参数传递给模板方法