【问题标题】:Intellisense fails for boost::shared_ptr with Boost 1.40.0 in Visual Studio 2008Intellisense 在 Visual Studio 2008 中使用 Boost 1.40.0 的 boost::shared_ptr 失败
【发布时间】:2012-07-24 18:46:58
【问题描述】:

我无法让智能感知自动完成 boost 1.40.0 的共享指针。 (它适用于 Boost 1.33.1。)这是一个简单的示例项目文件,其中自动完成功能不起作用:

#include <boost/shared_ptr.hpp>

struct foo
{ bool func() { return true; }; };

void bar() {
    boost::shared_ptr<foo> pfoo;
    pfoo.get();      // <-- intellisense does not autocomplete after "pfoo."
    pfoo->func();    // <-- intellisense does not autocomplete after "pfoo->"
}

当我右键单击 shared_ptr 并执行“转到定义”时,它会将我带到 &lt;boost/exception/exception.hpp&gt; 中 shared_ptr 类的前向声明。它确实将我带到了&lt;boost/smart_ptr/shared_ptr.hpp&gt; 中的实际定义。但是,它编译得很好,并且自动完成对“boost::”工作得很好。此外,对于 boost::scoped_ptr 和 boost::shared_array,自动完成功能也很好。

有什么想法吗?

【问题讨论】:

    标签: c++ visual-studio-2008 boost intellisense shared-ptr


    【解决方案1】:

    Intellisense 有自己的编译器,它可以容忍代码错误(它必须能够理解不完整的代码),但有时根本无法正确解析正确的代码。后者对于要求苛刻的模板代码尤其如此(因为 boost 是臭名昭著的)。

    要么接受它,要么等到 Intellisense 使用“普通”编译器(是为 VC10 或之后的版本宣布的?),或者尝试Visual Assist 的最新版本是否更好。

    【讨论】:

      【解决方案2】:

      我最近也遇到了这个问题并去寻找答案。我只发现有人说 Intellisense 将在 VC10 中得到改进,或者我现在应该使用 Visual Assist 改进它。我不喜欢这些答案,所以我做了一些实验。这是解决大部分问题的解决方案(至少它解决了 shared_ptr 的 scoped_ptr 没有的问题)。

      解决方案:

      在 exception.hpp 中更改 Intellisense 跳转到的前向声明以包含模板参数名称 T。

      改变

      template <class>
      class shared_ptr;
      

      template <class T>
      class shared_ptr;
      

      似乎 Intellisense 认为没有模板参数名称的定义是一个单独的类,这是 shared_ptr 和 scoped_ptr 之间差异的根源。

      现在,我提到这并没有解决我的所有问题。有时在头文件中声明的模板化对象不会在 cpp 文件中保留模板类型。

      例如

      // file.h
      #include <boost/shared_ptr.hpp>
      
      struct foo
      {
          void funcA() {}
      };
      
      struct bar
      {
          void funcB();
          boost::shared_ptr<foo> pfoo;
      };
      

      然后在cpp文件中

      // file.cpp
      #include "file.h"
      
      void bar::funcB()
      {
          pfoo.get();      // <-- intellisense does autocomplete after "pfoo."
          pfoo->func();    // <-- intellisense does not autocomplete after "pfoo->"
      }
      

      无论如何,这是我们仍然存在的问题的未经测试的精简示例,但这种情况远不常见,因此我们可以忍受它,直到 Intellisense 改进。

      【讨论】:

        【解决方案3】:

        不管怎样,VC++ 2010 附带了a separate (EDG) compiler for Intellisense。你试过 VS2010 的 Boost 1.40 吗?

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-02-28
          • 1970-01-01
          • 2015-04-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多