以下代码编译时带有错误消息:
@> g++ test.cpp
test.cpp: In member function 'void testit<E>::print()':
test.cpp:79: error: 'COL' is not a class or namespace
test.cpp:83: error: expected `;' before 'b2'
如果我使用 COL::columns; 访问静态成员,它不会编译成功。相反,通过 SelectColumn::SELECT_COLS::columns 访问静态成员;会好的!
struct AllColumns
{
static const char columns[];
};
const char AllColumns::columns[] = "*";
struct MemoryColumns
{
static const char columns[];
};
const char MemoryColumns::columns[] = "data,data_expire_time";
template<typename E>
struct SelectColumn
{
public:
typedef unsigned BIGT;
typedef AllColumns SELECT_COLS;
};
template<>
struct SelectColumn<int>
{
public:
typedef int BIGT;
typedef MemoryColumns SELECT_COLS;
};
template<typename E>
class testit
{
public:
typename SelectColumn<E>::SELECT_COLS COL;
typename SelectColumn<E>::BIGT BIG;
void print()
{
string str_a = COL::columns; //compile error here!
string str_b = SelectColumn<E>::SELECT_COLS::columns; // OK
BIG b2 = 10; //compile error here!
typename SelectColumn<E>::BIGT b = 12; // OK
}
};
如果我想使用 COL::columns 如何解决它?谢谢!