模板种继承

模板类继承

template<class TTable, class TGTP>
class CCmQry
{
public:
CCmQry(const char* szField, TGTP* pGTP)
: m_pGTP(pGTP)
{

}

int is_empty(TTable* p)
{
return false;
}

template<class TKey>
void query_table(TKey key)
{

}

public:
char m_szField[64];
TGTP* m_pGTP;
};

template<class TTable, class TGTP, class TSubQry>
class CCmQryParent : public CCmQry<TTable, TGTP>
{
    //typedef CCmQry< TTable,  TGTP> Base;
public:
CCmQryParent(const char* szField, TGTP* pGTP, TSubQry* pSubQry)
: CCmQry<TTable, TGTP>(szField, pGTP)
, m_pSubQry(pSubQry)
{
}

template<class TKey>
void query_table(TKey key)
{
        //Base::m_szField[10] = 0;
        m_szField[10] = 0;
}

public:
TSubQry* m_pSubQry;
};


int main()
{
    return 0;
}



template<class TTable, class TGTP>
class CCmQry
{
public:
CCmQry(const char* szField, TGTP* pGTP)
: m_pGTP(pGTP)
{

}

int is_empty(TTable* p)
{
return false;
}

template<class TKey>
void query_table(TKey key)
{

}

public:
char m_szField[64];
TGTP* m_pGTP;
};

template<class TTable, class TGTP, class TSubQry>
class CCmQryParent : public CCmQry<TTable, TGTP>
{
    typedef CCmQry< TTable,  TGTP> Base;
public:
CCmQryParent(const char* szField, TGTP* pGTP, TSubQry* pSubQry)
: CCmQry<TTable, TGTP>(szField, pGTP)
, m_pSubQry(pSubQry)
{
}

template<class TKey>
void query_table(TKey key)
{
        Base::m_szField[10] = 0;
        //m_szField[10] = 0;
}

public:
TSubQry* m_pSubQry;
};


int main()
{
    return 0;
}


第一段代码编译报错
test.cpp: In member function 'void CCmQryParent<TTable, TGTP, TSubQry>::query_table(TKey)':
test.cpp:42: error: 'm_szField' was not declared in this scope
第二段代码就可以,不知道是为什么?
既然已经是public继承了,那就应该可以直接使用啊?请指点下

------解决方案--------------------
对于模板类,unqualified name lookup 默认是不搜索基类域的,所以第一种找不到,然后报错。
第二种用的是 qualified name lookup,因此就能找到了。
其实你 using 一下,或者写 this->m_szField 也能找到。