meow00
asked on
error: class type redefinition ....
Hi Experts,
I got a "class type redefinition" error in the following code. (in VC++). Does anyone know what did I do wrong ??? thanks !!!
// MeowObject.cpp: implementation of the MeowObject class.
//
////////////////////////// ////////// ////////// ////////// ////////// ////
#include "stdafx.h"
#include "MeowObject.h"
class MeowObject{
////////////////////////// ////////// ////////// ////////// ////////// ////
// Construction/Destruction
////////////////////////// ////////// ////////// ////////// ////////// ////
private:
int _x, _y ;
MeowObject::MeowObject()
{
}
MeowObject::~MeowObject()
{
}
public:
void set_x(int x){_x =x ;}
void set_y(int y){_y =y ;}
int get_x(){return _x ;}
int get_y(){return _y ;}
};
I got a "class type redefinition" error in the following code. (in VC++). Does anyone know what did I do wrong ??? thanks !!!
// MeowObject.cpp: implementation of the MeowObject class.
//
//////////////////////////
#include "stdafx.h"
#include "MeowObject.h"
class MeowObject{
//////////////////////////
// Construction/Destruction
//////////////////////////
private:
int _x, _y ;
MeowObject::MeowObject()
{
}
MeowObject::~MeowObject()
{
}
public:
void set_x(int x){_x =x ;}
void set_y(int y){_y =y ;}
int get_x(){return _x ;}
int get_y(){return _y ;}
};
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It looks like you're mixing up class definition and implementation.
Unlike in languages like Ruby, you cannot change the definition of a C++ class, once it is defined.
Do definitions like
private:
int _x, _y ;
public:
void set_x(int x){_x =x ;}
void set_y(int y){_y =y ;}
int get_x(){return _x ;}
int get_y(){return _y ;}
in your .h file, and implement the methods like MeowObject::~MeowObject() and MeowObject::MeowObject() in your .cpp file. Leave out the "class MeowObject{ ... } " wrapper in your implementation.
Cheers!
Stefan