以下代码会出现编译错误:
template <typename T>
class Base
{
public:
void bar(){};
};
template <typename T>
class Derived : public Base<T>
{
public:
void foo() { bar(); } //Error
};
int main()
{
Derived *b = new Derived;
b->foo();
}
错误
第12行:错误:没有模板参数依赖于“bar”的参数,因此必须提供“bar”的声明
为什么会出现这个错误?
main()
中没有为Derived
指定模板参数。 - Nobody moving away from SE