Real code, stripped to simplest relevant parts:
template<class T>
class Ptr
{
private:
typedef Ptr this_type;
public:
typedef T element_type;
};
typedef Ptr<DataSet> DataSetPtr;
template<class BaseType>
class GPtr
{
///force BaseType to be a Ptr or subclass
typedef BaseType::element_type WrappedType;
public:
...
};
If I remove the reference to BaseType::element_type
it compiles fine, but with it in I get compile warnings/errors:
I am not even using GPtr
anywhere in my code as a specific templated type... simply including gptr.h leads to the problem.
What is wrong here?
You have to use the typename
disambiguator:
typedef typename BaseType::element_type WrappedType;
// ^^^^^^^^^
Without it, the compiler won't parse element_type
as the name of a type .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.