导读:
类型引用
以下是引用片段:
template
class Foo
{
typedef T::SomeType SomeType;
};
这段代码在VC++中一点问题也没有,但是GCC并不允许,因为它不知道T::SomeType是什么。你需要改为:
以下是引用片段:
template
class Foo
{
typedef typename T::SomeType SomeType;
};
通过typename T::SomeType告诉GCC,SomeType是一个类型名,而不是其他东西。
当然,这种情况不只是出现在typedef中。例如:
以下是引用片段:
template
void visit(const Container& cont)
{
for (Container::const_iterator it = cont.begin(); it != cont.end(); ++it)
...
}
这里的Container::const_iterator同样需要改为typename Container::const_iterator。
基类成员引用
以下是引用片段:
template
class Foo : public Base
{
public:
void foo() {
base_func();
m_base_member = 0;
类型引用
以下是引用片段:
template
class Foo
{
typedef T::SomeType SomeType;
};
这段代码在VC++中一点问题也没有,但是GCC并不允许,因为它不知道T::SomeType是什么。你需要改为:
以下是引用片段:
template
class Foo
{
typedef typename T::SomeType SomeType;
};
通过typename T::SomeType告诉GCC,SomeType是一个类型名,而不是其他东西。
当然,这种情况不只是出现在typedef中。例如:
以下是引用片段:
template
void visit(const Container& cont)
{
for (Container::const_iterator it = cont.begin(); it != cont.end(); ++it)
...
}
这里的Container::const_iterator同样需要改为typename Container::const_iterator。
基类成员引用
以下是引用片段:
template
class Foo : public Base
{
public:
void foo() {
base_func();
m_base_member = 0;