I have tried using a class template concept
but it does not seem to work ,
throws 2 error statements on compilation
i am new to the concept of class templates
what is the error in my program ???
/////
Error 663: "templ2.cpp", line 15 # Expected template arguments following template name 'student'.
void student::add()
^^^^^^^
Error 553: "templ2.cpp", line 31 # Expected type arguments to follow class template name.
student s1;
Code:#include<iostream.h> template <class T> class student { T rollno; T mark1; T mark2; public: void add(); /* function prototype */ }; template <class T> void student::add() { T total; cout<<"enter the rollno of the student"; cin>>rollno ; cout<<"enter the mark in the first subject "; cin>>mark1; cout<<"enter the mark in the second subject "; cin>>mark2; total = mark1 + mark2; cout<<" the total in the two subjects is "<<total; cout<<" the roll no is "<<rollno; }; int main() { student s1; s1.add(); return 0; }



LinkBack URL
About LinkBacks


