954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Constructor error

After creating a class called student i aslo include a constructor and destructor the implementation code is shown below.

student::student(){;}
student:: ~student(){;}

but i still have an error message as -
" return type specification for constructor invalid"
can any one help me figure whats wrong ??

haven_u
Light Poster
36 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

Do you have any other constructors? (overloaded)
If not, post more code.

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

Implementation looks pretty fine. Post the declaration too.
BTW, the declaration should be

class student{
public:
        student();
        ~student();
        //other stuff
}
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
 

[psychic debugging]
You probably forgot to terminate your class definition with a semicolon and the constructor definition immediately follows it. The following code should produce a similar error:

class foo {
public:
  foo();
}

foo::foo() {}

The error is saying that the constructor for foo is trying to use the type foo (specified by a class definition) as the return type for the constructor. However, a constructor doesn't have a return type, so the compiler issues a diagnostic.
[/psychic debugging]

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

thanks for the help...

haven_u
Light Poster
36 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You