VC.NET下error C2533: 构造函数不能有返回类型把函数里的代码注释掉也没用。class RSBase
{
public:
RSBase(void);
virtual ~RSBase(void); int m_nTopLeftX;
int m_nTopLeftY;
int m_nLength; bool m_bMoveLeft;
bool m_bMoveRight;
bool m_bMoveDown;
bool m_bDeformation;
int m_nDeformCount;
RSArr **m_pDefaultRS;
RSArr *m_pCurrentRS;
};class RSLeftL :
public RSBase
{
public:
RSLeftL(void);
~RSLeftL(void); static const int m_nCount = 4;
};RSLeftL::RSLeftL(void)
{ //这里是出现错误的行
m_nTopLeftX = 4;
m_nTopLeftY = 2;
m_nLength = 3; m_bMoveLeft = false;
m_bMoveRight = false;
m_bMoveDown = false;
m_bDeformation = false;
m_nDeformCount = 0; int init[4][3][3] = {
{0, 2, 0, 0, 2, 0, 0, 2, 2},
{0, 0, 2, 2, 2, 2, 0, 0, 0},
{2, 2, 0, 0, 2, 0, 0, 2, 0},
{0, 0, 0, 2, 2, 2, 2, 0, 0}
}; m_pDefaultRS = new RSArr*[m_nCount];
for(int i = 0; i < m_nCount; i++)
{
m_pDefaultRS[i] = new RSArr(m_nLength);
m_pDefaultRS[i]->Init(&init[i][0][0]);
} m_pCurrentRS = m_pDefaultRS[0];
}
{
public:
RSBase(void);
virtual ~RSBase(void); int m_nTopLeftX;
int m_nTopLeftY;
int m_nLength; bool m_bMoveLeft;
bool m_bMoveRight;
bool m_bMoveDown;
bool m_bDeformation;
int m_nDeformCount;
RSArr **m_pDefaultRS;
RSArr *m_pCurrentRS;
};class RSLeftL :
public RSBase
{
public:
RSLeftL(void);
~RSLeftL(void); static const int m_nCount = 4;
};RSLeftL::RSLeftL(void)
{ //这里是出现错误的行
m_nTopLeftX = 4;
m_nTopLeftY = 2;
m_nLength = 3; m_bMoveLeft = false;
m_bMoveRight = false;
m_bMoveDown = false;
m_bDeformation = false;
m_nDeformCount = 0; int init[4][3][3] = {
{0, 2, 0, 0, 2, 0, 0, 2, 2},
{0, 0, 2, 2, 2, 2, 0, 0, 0},
{2, 2, 0, 0, 2, 0, 0, 2, 0},
{0, 0, 0, 2, 2, 2, 2, 0, 0}
}; m_pDefaultRS = new RSArr*[m_nCount];
for(int i = 0; i < m_nCount; i++)
{
m_pDefaultRS[i] = new RSArr(m_nLength);
m_pDefaultRS[i]->Init(&init[i][0][0]);
} m_pCurrentRS = m_pDefaultRS[0];
}
'identifier' : constructors not allowed a return typeThe specified constructor was declared with a return type.A constructor does not return a value and has no return type. A return type of void is not allowed.The following is an example of this error.class X
{
public:
void X( void ) { ... }; // error, return type declared
X( void ) { ... }; // OK, no return type declared
};
public RSBase
{
public:
RSLeftL(void);//!!!ok
~RSLeftL(void); static const int m_nCount = 4;
};RSLeftL::RSLeftL()// !!!void not allowed here
{ //这里是出现错误的行
m_nTopLeftX = 4;
m_nTopLeftY = 2;
}
{
public:
RSBase();
virtual ~RSBase(void); int m_nTopLeftX;
int m_nTopLeftY;
int m_nLength; bool m_bMoveLeft;
bool m_bMoveRight;
bool m_bMoveDown;
bool m_bDeformation;
int m_nDeformCount;
RSArr **m_pDefaultRS;
RSArr *m_pCurrentRS;
};class RSLeftL :
public RSBase
{
public:
RSLeftL(void);
~RSLeftL(void); static const int m_nCount = 4;
};RSLeftL::RSLeftL()
{ //这里是出现错误的行
m_nTopLeftX = 4;
m_nTopLeftY = 2;
m_nLength = 3; m_bMoveLeft = false;
m_bMoveRight = false;
m_bMoveDown = false;
m_bDeformation = false;
m_nDeformCount = 0; int init[4][3][3] = {
{0, 2, 0, 0, 2, 0, 0, 2, 2},
{0, 0, 2, 2, 2, 2, 0, 0, 0},
{2, 2, 0, 0, 2, 0, 0, 2, 0},
{0, 0, 0, 2, 2, 2, 2, 0, 0}
}; m_pDefaultRS = new RSArr*[m_nCount];
for(int i = 0; i < m_nCount; i++)
{
m_pDefaultRS[i] = new RSArr(m_nLength);
m_pDefaultRS[i]->Init(&init[i][0][0]);
} m_pCurrentRS = m_pDefaultRS[0];
}
c++规定构造函数和析构函数是没有返回的
cbc(逍遥子)的回复:
X( void ) { ... }; // OK, no return type declared我的代码中,并没有返回类型类型啊。
难道是编译器的bug?
1.restart VC
2.restart pc
2.reinstall VC
3.reinstall os
public RSBase
{
public:
RSLeftL(void);
virtual ~RSLeftL(void);//<-!!! static const int m_nCount = 4;
};你的析构函数要“虚”,原因翻书吧
/**h文件**/class RSBase
{
public:
RSBase();
virtual ~RSBase(); int m_nTopLeftX;
int m_nTopLeftY;
int m_nLength; bool m_bMoveLeft;
bool m_bMoveRight;
bool m_bMoveDown;
bool m_bDeformation;
int m_nDeformCount;};class RSLeftL : public RSBase
{
public:
RSLeftL();
~RSLeftL(); static const int m_nCount;// = 4;
};//c++规定构造函数和析构函数是没有返回的/****另外一个cpp文件***/#include "stdafx.h"
#include "FileChanger.h"
#include "test1.h"
const int RSLeftL::m_nCount = 4;
RSLeftL::RSLeftL()
{ //这里是出现错误的行
m_nTopLeftX = 4;
m_nTopLeftY = 2;
m_nLength = 3; m_bMoveLeft = false;
m_bMoveRight = false;
m_bMoveDown = false;
m_bDeformation = false;
m_nDeformCount = 0;
}
基类中析构函数已经声明为析构
所以派生类中析构函数也必然是虚函数
virtual关键字可加可不加现在怀疑楼主得vc编译器有问题
只要能解决问题不就行了