class template specialization - incomplete type
Dec 21, 2010 at 2:40pm UTC
Hi,
I have a problem, this code won't compile. It says the class foo<10, int> is incomplete...
Can someone here tell me what's wrong, and how to correct it?
(Never mind the names):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <iostream>
using namespace std;
// general template
template <int N, typename type>
class foo
{
public :
type arr[N];
public :
bool lol()
{
cout << "lol" << endl;
return true ;
}
};
// supposed to overload function lol() if the first template parameter is 10
template <typename type>
bool foo<10, type>::lol()
{
cout << "lol it's 10" << endl;
return false ;
}
int main()
{
foo<10, int > bar;
cout << bar.lol() << endl;
foo<5, int > baz;
cout << baz.lol() << endl;
return 0;
}
Dec 21, 2010 at 5:57pm UTC
Partial Specialization of template functions are not allowed
EDIT:
I was going to add something but I'll leave it for the moment.
Last edited on Dec 21, 2010 at 6:28pm UTC
Topic archived. No new replies allowed.