You have some mistakes:
line 2:
include namespace std;
should be
using namespace std;
line 22: In your code you are trying to pass to cout the return value of member function
dd.display();
.
What's the return value of that function:
void
meaning it does not return a thing. So your compiler complains and tries to find out a solution for this. Error messages sometimes are not vary helpful so you must try to see the whole picture.
Possible solutions are:
1) redeclare your member function to return an object cout knows how to treat: int, float or even some object class you have defined BUT also implemented operetor<< for your class. If that sounds too much stick for now with build-in types like int, floats, arrays etc.
2) Just do what you have done: define your member function to pass to cout some value. This will happen whenever it's called (so also on line 22 but there compiler complains for other reason mentioned before). So that's why line 24 works fine.
Finally (not an error by the strict definition of errors) but try to use initialization list instead of initializing your variables inside constructor body:
line 10 should be
1 2 3
|
alpha(int d)
:data(d)
{}
|
instead of
alpha(int d){ data = d;}
It has the same effect but it's better to use the first approach (for reason that will become apparent when not build-in types are used)