I have a class called teacher
class Teacher
{
private:
int ID;
string qualification;
double salary;
Date DOB;
Date dateJoined;
public:
Teacher();
void setTeacher (int, string, double);
string getQualification();
void displayTeacher();
}
//This is my constructor
Teacher::Teacher()
{
ID = 0;
qualification =" " ;
salary=0.0;
}
I got an error C2533: 'Teacher::{ctor}' : constructors not allowed a return type. where did i go wrong?
You did not put a semicolon after the class definition.
This confuses the parser, which now thinks you're writing something like this:
class {} functionName(args) {}
^^^^^^^^ ^^^^^^^^^^^^
return type constructors
defined are functions, but
in-place they don't have
(oops) return types!
(oops)
Modern GCC (say, 4.9.2) is quite clear about this problem:
class Teacher
{
Teacher();
}
Teacher::Teacher()
{}
// main.cpp:3:1: error: new types may not be defined in a return type
// class Teacher
// ^
// main.cpp:3:1: note: (perhaps a semicolon is missing after the definition of 'Teacher')
// main.cpp:8:18: error: return type specification for constructor invalid
// Teacher::Teacher()
// ^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With