Typedef in class
There is such code:
template <class T>
class SomeClass{
typedef boost::shared_ptr<T> sPtr;
typedef std::vector<sPtr> c;
typedef c::iterator cIt; // here is the problem
};
and the error is:
main.cpp:23: error: type ‘std::vector<boost::shared_ptr<X>, std::allocator<boost::shared_ptr<X> > >’ is not derived from type ‘SomeClass<T>’
main.cpp:23: error: expected ‘;’ before ‘cIt’
How to use typedef to templated parameters 开发者_如何学编程in class?
EDIT:
I figured it out, for g++ that must be:
typedef typename c::iterator cIt; // here is the problem
Please close it.
The problem is that c::iterator
is a qualified-id, and the type of c
depends on a template paramater. According to §14.6/3
:
When a qualified-id is intended to refer to a type that is not a member of the current instantiation and its nested-name-specifier refers to a dependent type, it shall be prefixed by the keyword typename ...
精彩评论