#include <iostream>
usingnamespace std;
class number
{
int a,b;
public:
number();
~number();
int showdata();
};
number::number()
{
cout<<" Constructor Called : "<<endl;
a=50;
b=25;
}
number::~number()
{
cout<<" Destructor Called... "<<endl;
}
number::int showdata()
{
cout<<"A = "<<a<<endl;
cout<<"B = "<<b<<endl;
cout<<"The Product is : "<<a*b<<endl;
return 0;
}
int main()
{
number n;
n.showdata();
return 0;
}
This is a program to show the working of constructor and destructor. Can someone Please help me how to solve that error. The error come in the line 10 i.e. ~integer(); The token error has gone . the new error is expected unqualified-id before 'int' in line 22.
This is the error
error: expected unqualified-id before 'int'
Thanks Guys. Did what you said by changing the class name and also with the return type as void .But another error came expected unqualified-id before 'void' .
/*
number::int showdata() {
You can't do this, the type comes BEFORE the class name.
Try this instead: */
int number::showdata() {
// Print the data
}
Also, in your function "showdata", why bother returning at all? You may as well declare "showdata()" as of type void. (Don't forget to also get rid of line 27 if you are going to do that.)