error expected class-name before '(' token

Write your question here.
Updated Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace 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'
Last edited on
Hi Sainatarajan,

The constructor / destructor functions must have the same name as the class.

When posting compiler errors, please post them in full.

Cheers
apart from that you missed to mention the return type for showdata function
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' .
Please edit your original post to show the updated code, and post the error test in full.
Updated. Please Help Guys.
On line 22, you have an error:
1
2
3
4
5
6
7
/*
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.)
@NT3 and others
Thank You Very Much !!!.... The Program Worked As Expected.
Topic archived. No new replies allowed.