【问题标题】:Why so many errors here in typedef?为什么 typedef 中有这么多错误?
【发布时间】:2011-06-18 16:54:09
【问题描述】:

从此:

   // parts of c++0x std
    #include <boost/bind.hpp> 
    #include <boost/function.hpp>

    #ifndef _IGraphElement_h_
    #define _IGraphElement_h_

    using namespace std ;
    template <typename DataType >
    class IGraphElement : public IGraphElementBase{

        typedef boost::function<void(DataType)>   Function;
        typedef std::vector<Function>      FunctionSequence;  // (line *)
        typedef FunctionSequence::iterator FunctionIterator; // (line **)
//...
};

C2146和C4430同时上线**!(如何解决?

【问题讨论】:

  • 当您遇到模板和typedef 错误时,您有 85% 的机会忘记了typename:)

标签: c++ visual-studio visual-studio-2008 boost


【解决方案1】:
typedef FunctionSequence::iterator FunctionIterator; // (line **)

这应该写成,

typedef typename FunctionSequence::iterator FunctionIterator;

由于iterator 是从属名称,所以typename 是必需的!

在此处阅读依赖名称:

【讨论】:

    【解决方案2】:
    • 您需要一个typename,正如其他人提到的那样(read this 了解更多详情)。
    • dataElement = DataElement 之后的 InitGet 方法中您忘记了 ;
    • 您错过了一些标头,GraphItemMutexGraphItemMutexConditionVariableGraphWorker 对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-21
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多