0

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 ??

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by haven_u
Featured Replies
  • 1

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

  • 1

    Implementation looks pretty fine. Post the declaration too. BTW, the declaration should be [code=cpp]class student{ public: student(); ~student(); //other stuff }[/code] Read More

  • 1
    Narue 5,707   7 Years Ago

    [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: [code=cplusplus] class foo { public: foo(); } foo::foo() {} [/code] The error is saying that the constructor for foo is trying to … Read More

1

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

class student{
public:
        student();
        ~student();
        //other stuff
}
1

[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]

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.