template specialization

Joined
Dec 30, 2008
Messages
2
Reaction score
0
template <class T>
class demo
{
T x,y;
public:
demo(T a, T b) : x(a),y(b){}
T module1(){return 0;}
};

template <>
class demo<int>
{
int x, y;
public:
demo(int a, int b) : x(a),y(b){}
int module1();
};

template <>
int demo<int>::module1()
{
return (x%y);
}

int main()
{
demo<int> O1(200, 30);
cout<<O1.module1()<<endl;

demo<float> O2(200.50, 30.50);
cout<<O2.module1()<<endl;

return 0;
}


while compiling M getting the error:
error C2910: 'demo<int>::module' : cannot be explicitly specialized.

why?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top