scdmb
scdmb

Reputation: 15641

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.

Upvotes: 4

Views: 782

Answers (1)

Mankarse
Mankarse

Reputation: 40643

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 ...

Upvotes: 7

Related Questions