【发布时间】:2013-04-17 02:44:35
【问题描述】:
我有一个包含 Car 类实例的 Tran 类。如果程序在typedef 之前包含typename,则会产生错误:“expected nested-name-specifier before typedef”。如果它不包含typename,则会产生错误:“在'Tran::CarType::Model' 之前需要'typename',因为'Tran::CarType' 是一个依赖范围”。是什么导致了这个问题?
#include "Car.hpp"
template<typename A, typename B, typename C>
class Tran {
public:
typedef Car<A, B> CarType; //compilation error
typedef CarType::Model M; //compilation error
private:
CarType myCar;
}
【问题讨论】:
标签: c++ templates inheritance