3
的類成員的繼承,爲什麼T2給這個錯誤‘m_t’ was not declared in this scope
,而TB是好的?在下面的代碼中混合模板
而我仍然可以在使用模板的同時在T2中訪問T1的成員?
// All good
class TA
{
public:
TA() {}
protected:
int m_t;
};
class TB : public TA
{
public:
TB() {}
int get()
{ return m_t; }
protected:
};
// Error in T2
template<typename T>
class T1
{
public:
T1() {}
protected:
int m_t;
};
template<typename T>
class T2 : public T1<T>
{
public:
T2() {}
int get()
{ return m_t; }
protected:
};
試試'this-> m_t'。這是關於兩階段查找和依賴名稱。 – juanchopanza 2013-05-07 13:14:38
相關:http://stackoverflow.com/q/605497/951890 – 2013-05-07 13:16:21