c++ - unique_ptr 的取消引用运算符在 Eclipse 中不起作用

标签 c++ eclipse c++11 eclipse-cdt unique-ptr

按照 this post 中的步骤操作后我设法让 Eclipse (Indigo) 识别 unique_ptr(和其他 C++11 新东西)。问题是 operator-> for unique_ptr 似乎在 Eclipse 中不受支持。这里有一个例子:

class Foo { void bar() { /* ... */ } };

std::unique_ptr<Foo> foo;
(*foo).bar(); // 1
foo->bar();   // 2

Case 1 按预期工作:没有错误并且自动完成工作。然而,对于案例 2,Eclipse 将语句标记为错误(“无法解析方法 'bar'”),而且 foo-> 的自动完成功能不起作用。

最有趣的是,我对 std::shared_ptr 没有任何问题。它只发生在 std::unique_ptr 上。

有没有人遇到过同样的问题?有谁知道解决它的方法吗?

编辑:仅出于澄清目的,上面显示的代码片段的编译过程没有问题。所以,问题不在编译器本身,而在 Eclipse 上。

最佳答案

我终于找到了bug report在 CDT 中描述了我正在遭受的同样的问题。到目前为止,还没有真正解决该问题的方法,但该错误报告中解释了一种解决方法:

Yes, GCC 4.5 is the latest GCC version whose library headers can be accurately indexed by CDT. The main reason for failing to index 4.6 headers is CDT's lack of support for 'constexpr' and 'nullptr', which are used extensively in the 4.6 headers (any chance of that being implemented for Juno, by the way?).

I have worked around this by having both GCC 4.5 and 4.6 installed on my system, and pointing CDT to 4.5's headers (by setting the compiler invocation command to 'g++-4.5' in Discovery Options) while actually compiling with 4.6.

关于c++ - unique_ptr 的取消引用运算符在 Eclipse 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11154048/

相关文章:

c++检查基引用的大多数派生类是否具有另一个基

java - EMF Compare 代码的编译问题

java - GWTP Eclipse 插件生成空演示者

pointers - 如何将类型存储为成员?

c++ - libconfig 未定义对 libconfig::Config::Config() 的引用

c++ - 如何配置 ImageMagick 不使用任何临时文件?

c++ - decltype 在函数参数中的使用

c++ - 插入通用容器不起作用

c++ - C++可变参数函数对参数进行原位排序

eclipse - 为 Spring MVC Web 应用程序设置起始页?