Generic Class

Hi

I am a beginner in c++, please can someone tell me what's wrong with this code ? It gave me this error :'MyClass<T>' should be preceded by ':'

#include <iostream>
using namespace std;

template <class T> class MyClass {
T x,y;
public
MyClass(T a, T b)
{
x=a;
y=b;
}
T div() {return x/y;}
};

int main()
{
MyClass<double> d_ob(10.0,3.0);
cout << "double division: "<< d_ob.div() << "\n";

MyClass<int> i_ob(10,3);
cout << "integer division: "<< i_ob.div() << "\n";

return 0;
}

Thank you very much
when in a class body, access keywords (public, protected, private) need to be followed by a colon:

1
2
3
4
5
template <class T> class MyClass {
  T x,y;
  public:  // <- need a colon here
  MyClass(T a, T b)
...
your public doesn't have a :
Last edited on
Thank you guys, I' m very sorry for this stupid question, but i have to learn
Topic archived. No new replies allowed.