Classes Issue

Started by
17 comments, last by Paulius Maruska 17 years, 11 months ago
I am working with MVC++ 2005 Express Edition, and am getting the error C2533 when I try to compile the code.

------ Build started: Project: BiggerFish, Configuration: Release Win32 ------
Compiling...
Fish.cpp
.\Fish.cpp(11) : error C2533: 'Fish::{ctor}' : constructors not allowed a return type
Build log was saved at "file://c:\Documents and Settings\Hillam\My Documents\Visual Studio 2005\Projects\BiggerFish\BiggerFish\Release\BuildLog.htm"
BiggerFish - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
When I typed C2533 in the help files, it told me this: int X::X() { } //C2533. X::X() { } //OK. The problem is that I haven't specified a return balue for this function, so why is it telling me I'm not allowed to? Here is my class, Fish.cpp (Fish.h is somewhere else, and DOES exist, so don't tell me that is the problem):

////////////////////////////////////////////////
// Fish()
////////////////////////////////////////////////
Fish::Fish(void)
{
	i_Level = 0;
	i_Exp = 0;
	i_MoveSpeed = 0;
	c_MoveDirection;
	b_IsBubble = FALSE;
}

////////////////////////////////////////////////
// ~Fish()
////////////////////////////////////////////////
Fish::~Fish(void)
{
}

Advertisement
Can you post your header file code too?
My guess: You have a malformed statement right BEFORE the constructor. Like, perhaps near the end of a header file included by the source file which defines the constructor. Like, perhaps you've left the semicolon off the end of a class definition? For instance, the definition of the Fish class? HMMMM?


When confronted with an error message that seems incorrect, always consider the lines before the line causing the error. After all, C/C++ really has no concept of "lines", just of statements. Unterminated things can make a "line" quite long.
Well, I'm pretty sure it ISN't the header file because it was working fine but I accidentally deleted the Fish.cpp that went with it, and as a result, had to rewrite it. Nevertheless, I'll try posting the Fish.h file as well.
Post Fish.cpp, while you're at it.
Also you don't have to declare a "void" parameter list in C++, and actually it is encouraged not to put it.
Here is the build log:

------ Build started: Project: BiggerFish, Configuration: Release Win32 ------Compiling...Fish.cpp.\Fish.cpp(11) : error C2533: 'Fish::{ctor}' : constructors not allowed a return typeBuild log was saved at "file://c:\Documents and Settings\Hillam\My Documents\Visual Studio 2005\Projects\BiggerFish\BiggerFish\Release\BuildLog.htm"BiggerFish - 1 error(s), 0 warning(s)========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Fish.cpp:

////////////////////////////////////////////////// Fish.cpp////////////////////////////////////////////////#include "Fish.h"////////////////////////////////////////////////// Fish()////////////////////////////////////////////////Fish::Fish(void){	i_Level = 0;	i_Exp = 0;	i_MoveSpeed = 0;	c_MoveDirection;	b_IsBubble = FALSE;}////////////////////////////////////////////////// ~Fish()////////////////////////////////////////////////Fish::~Fish(void){}////////////////////////////////////////////////// SetLevel()////////////////////////////////////////////////void Fish::SetLevel(int Level){	i_Level = Level;}////////////////////////////////////////////////// GetLevel()////////////////////////////////////////////////int Fish::GetLevel(){	return i_Level;}///////////////////////////////////////////////// SetExp()///////////////////////////////////////////////void Fish::SetExp(int Exp){	i_Exp = Exp;}///////////////////////////////////////////////// GetExp()///////////////////////////////////////////////int Fish::GetExp(){	return i_Exp;}///////////////////////////////////////////////// SetMoveSpeed()///////////////////////////////////////////////void Fish::SetMoveSpeed(int MoveSpeed){	i_MoveSpeed = MoveSpeed;}///////////////////////////////////////////////// GetMoveSpeed()///////////////////////////////////////////////int Fish::GetMoveSpeed(){	return i_MoveSpeed;}///////////////////////////////////////////////// SetMoveDirection()///////////////////////////////////////////////void Fish::SetMoveDirection(char MoveDirection){	c_MoveDirection = MoveDirection;}///////////////////////////////////////////////// GetMoveDirection()///////////////////////////////////////////////char Fish::GetMoveDirection(){	return c_MoveDirection;}///////////////////////////////////////////////// SetIsBubble()///////////////////////////////////////////////void Fish::SetIsBubble(bool IsBubble){	b_IsBubble = IsBubble;}///////////////////////////////////////////////// GetIsBubble()///////////////////////////////////////////////bool Fish::GetIsBubble(){	return b_IsBubble;}///////////////////////////////////////////////// SetLocationX()///////////////////////////////////////////////void Fish::SetLocationX(int LocationX){	i_LocationX = LocationX;}///////////////////////////////////////////////// GetLocationX()///////////////////////////////////////////////int Fish::GetLocationX(){	return i_LocationX;}///////////////////////////////////////////////// SetLocationY()///////////////////////////////////////////////void Fish::SetLocationY(int LocationY){	i_LocationY = LocationY;}///////////////////////////////////////////////// GetLocationY()///////////////////////////////////////////////int Fish::GetLocationY(){	return i_LocationY;	}


And Fish.h:

/////////////////////////////////////////////////////////////// Fish.h/////////////////////////////////////////////////////////////#pragma once#include <windows.h>class Fish{	protected:		int i_Level;		int i_Exp;		int i_MoveSpeed;		char c_MoveDirection;		bool b_IsBubble;		int i_LocationX;		int i_LocationY;	public:		Fish(void);		~Fish(void);		void SetLevel(int Level);		int GetLevel();		void SetExp(int Exp);		int GetExp();		void SetMoveSpeed(int MoveSpeed);		int GetMoveSpeed();		void SetMoveDirection(char MoveDirection);		char GetMoveDirection();		void SetIsBubble(bool IsBubble);		bool GetIsBubble();		void SetLocationX(int LocationX);		int GetLocationX();		void SetLocationY(int LocationY);		int GetLocationY();}
...


Did you even read my first post? You know, the one where I correctly diagnosed the problem before you'd even posted the code, by reading your mind?
in the header file, you must put ; after the class declaration.
Quote:Original post by Sneftel
...


Did you even read my first post? You know, the one where I correctly diagnosed the problem before you'd even posted the code, by reading your mind?


Of course I read it! I just went through my code though and couldn't find any errors in the .h file so I posted everything to see if one of you guys could find it. Also, I added that ; after declaring the class (I thought that was illegal!) and guess what? 30 more errors pop up, so I'll have a look at those if it is legal to put the semicolon where you said.

This topic is closed to new replies.

Advertisement