Why so many errors here in typedef?

2019-07-15 10:29发布

问题:

from this:

   // 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 **)
//...
};

I get C2146 and C4430 on line ** at the same time!( How to fix such thing?

回答1:

typedef FunctionSequence::iterator FunctionIterator; // (line **)

This should be written as,

typedef typename FunctionSequence::iterator FunctionIterator;

Since iterator is a dependent name, so typename is required!

Read about dependent name here:

  • Name binding and dependent names (C++ only)
  • Dependent Names (scroll down and read this section - better if you read the complete article)


回答2:

  • You need a typename as mentioned by others (read this for more details).
  • You forgot ; in InitGet method after dataElement = DataElement.
  • You miss some headers, GraphItemMutex, GraphItemMutexConditionVariable and GraphWorker objects.