我有一個類Tran包含一個類Car的實例。如果程序包括typename
typedef
之前,它會產生一個錯誤:「預計嵌套名稱 - 符typedef
之前」。如果它不包含typename
,則會在'Tran :: CarType :: Model'之前產生一個錯誤:「需要'typename',因爲'Tran :: CarType'是一個從屬範圍」。什麼導致了這個問題?在C++中產生typename和typedef相關錯誤的模板類?
#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;
}
我應該猜到,這個問題是你的...... * template typedef * :) –
@DavidRodríguez-dribeas-我在想,當我輸入這個。 :-) – templatetypedef