1
此代碼不能在GCC編譯:
template <typename T>
struct Base
{
public:
int x;
};
template <typename B>
struct Middle : public B
{
};
template <typename T>
struct Sub : public Middle<Base<T> >
{
public:
void F()
{
x=1; // error: ‘x’ was not declared in this scope
}
};
如果任Base
或Sub
沒有模板類,它不會抱怨。 VC處理它。
爲什麼?
[模板繼承問題]的副本(http://stackoverflow.com/questions/2982660/problem-with-template-inheritance) – 2010-06-14 21:08:49