本文介绍了C ++错误C2533,ctor:构造函数不允许返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个叫老师的班
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;
}
我收到一个错误C2533:'Teacher :: {ctor}':constructor不允许返回类型。
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)
现代GCC问题:
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()
// ^
这篇关于C ++错误C2533,ctor:构造函数不允许返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!