unique_ptr没有成员函数

unique_ptr has no member function

本文关键字:成员 函数 ptr unique      更新时间:2023-10-16

我正在将我的 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();