M
mrstephengross
Ok, I've got a class with two template parameters (A and B), and a
member function foo(). I want to specialize foo for a particular class
A. Is this possible? The following code shows an example:
=====================================
template<typename A, typename B>
class Foo
{
int foo() { return 5; }
};
template<typename B>
int Foo<int, B>::foo() { return 6; }
int main()
{
return 0;
}
======================================
The above example doesn't compile; g++ reports the following error:
test.cpp:11: error: no `int Foo<int, B>::foo()' member function
declared in class `Foo<int, B>'
test.cpp:11: error: template definition of non-template `int Foo<int,
B>::foo()'
I take it this means I can't write function implementations for class
specializations if the class specialization hasn't been declared...?
Thanks,
--Steve
member function foo(). I want to specialize foo for a particular class
A. Is this possible? The following code shows an example:
=====================================
template<typename A, typename B>
class Foo
{
int foo() { return 5; }
};
template<typename B>
int Foo<int, B>::foo() { return 6; }
int main()
{
return 0;
}
======================================
The above example doesn't compile; g++ reports the following error:
test.cpp:11: error: no `int Foo<int, B>::foo()' member function
declared in class `Foo<int, B>'
test.cpp:11: error: template definition of non-template `int Foo<int,
B>::foo()'
I take it this means I can't write function implementations for class
specializations if the class specialization hasn't been declared...?
Thanks,
--Steve