Skip to main content
gamedev.net
🔒 Locked

Odd Class Behavior

Started by jrmiller84 2 replies 750+ views
Original Post
jrmiller84
jrmiller84
So I've been researching this problem all weekend and can't seem to find an answer. I'm very familiar with classes but after all of the googling I can't seem to find the problem. On five of my functions in my base class, I get these errors:
c:\program files\jamesoft\pap\cbase.cpp(6) : error C2535: '__thiscall CBase::CBase(void)' : member function already defined or declared
        c:\program files\jamesoft\pap\cbase.h(12) : see declaration of 'CBase::CBase'
c:\program files\jamesoft\pap\cbase.cpp(53) : error C2535: 'void __thiscall CBase::MoveLeft(float)' : member function already defined or declared
        c:\program files\jamesoft\pap\cbase.h(33) : see declaration of 'MoveLeft'
c:\program files\jamesoft\pap\cbase.cpp(60) : error C2535: 'void __thiscall CBase::MoveRight(float)' : member function already defined or declared
        c:\program files\jamesoft\pap\cbase.h(34) : see declaration of 'MoveRight'
c:\program files\jamesoft\pap\cbase.cpp(67) : error C2535: 'void __thiscall CBase::MoveUp(float)' : member function already defined or declared
        c:\program files\jamesoft\pap\cbase.h(36) : see declaration of 'MoveUp'
c:\program files\jamesoft\pap\cbase.cpp(75) : error C2535: 'void __thiscall CBase::MoveDown(float)' : member function already defined or declared
        c:\program files\jamesoft\pap\cbase.h(37) : see declaration of 'MoveDown'



I know exactly what this error means but I can't see that being the case in my classes. To show what I mean, here is my class header file. Sorry for it being so lengthy, but It won't really get the point across without the files posted. I will also post the functions definitions after that.

//CBase.h
#ifndef INC_CBASE_H
#define INC_CBASE_H

#include <d3dx8.h>

class CBase {

	public:

		LPDIRECT3DTEXTURE8 ObjTexture;

		CBase();
		~CBase();

		void Width(float SentWidth) { CordWidth = SentWidth; }
		float Width() { return CordWidth; }

		void Height(float SentHeight) { CordHeight = SentHeight; }
		float Height() { return CordHeight; }

		void RelativeXPosition(float SentRelXPos) { RelXPos = SentRelXPos; }
		float RelativeXPosition() { return RelXPos; }
		
		void RelativeYPosition(float SentRelYPos) { RelYPos = SentRelYPos; }
		float RelativeYPosition() { return RelYPos; }

		void AbsoluteXPosition(float SentAbsXPos) { AbsXPos = SentAbsXPos; }
		float AbsoluteXPosition() { return AbsXPos; }
		
		void AbsoluteYPosition(float SentAbsYPos) { AbsYPos = SentAbsYPos; }
		float AbsoluteYPosition() { return AbsYPos; }

		void MoveLeft(float Distance);
		void MoveRight(float Distance);

		void MoveUp(float Distance);
		void MoveDown(float Distance);

		void SetHealth(int HP) { Health = HP; )
		int GetHealth() {return Health; }

		int Hurt(int HP_Loss) { Health -= HP_Loss; return Health; }

		bool LoadSettings(char* SettingFilePath);
		bool LoadTexture(char* TextureFilePath);

		void Color(int Red, int Green, int Blue);
		int Color(int ConstColor);
		
	private:

		float CordWidth;
		float CordHeight;
		
		float RelXPos;
		float RelYPos;

		float AbsXPos;
		float AbsYPos;

		int Health;

		int Texture_Height;
		int Texture_Width;

		int RGBRed;
		int RGBGreen;
		int RGBBlue;

};

#endif



Here is my source file that contains the definitions for each of those functions.

//CBase.cpp
#include <d3dx8.h>
#include <string.h>

#include "CBase.h"

CBase::CBase() { 
	
	ObjTexture = NULL; 
	Health = 100; 

}


bool CBase::LoadSettings(char* SettingFilePath) {

	CFIO* BaseSettings;
	BaseSettings = new CFIO("objects\\" + SettingFilePath);

	this->CordWidth((float)atoi(BaseSettings->GetSetting("Width")));
	this->CordHeight((float)atoi(BaseSettings->GetSetting("Height")));
	
	this->AbsoluteXPosition((float)atoi(BaseSettings->GetSetting("XPos")));
	this->AbsoluteYPosition((float)atoi(BaseSettings->GetSetting("YPos")));
	
	this->Color(atoi(BaseSettings->GetSetting("Red")), atoi(BaseSettings->GetSetting("Green")), atoi(BaseSettings->GetSetting("Blue")));

	return this->LoadTexture("objects\\" + BaseSettings->GetSetting("Texture"));

}

bool CBase::LoadTexture(char* TextureFilePath) {

	HBITMAP bit = 0;
	BITMAP bitmap;

	if (FAILED(D3DXCreateTextureFromFileEx(g_pD3DDevice, TextureFilePath, 0, 0, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, D3DCOLOR_XRGB(0, 255, 0), NULL, NULL, this->ObjTexture))) {

		return false;

	}

	bit = (HBITMAP) LoadImage(NULL, TextureFilePath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

	GetObject(bit, sizeof(BITMAP), &bitmap);

	this->Texture_Height = bitmap.bmHeight;
	this->Texture_Width = bitmap.bmWidth;

	return true;

}

void CBase::MoveLeft(float Distance) {
	
	this->RelXPos -= Distance;
	this->AbsXPos -= Distance;

}

void CBase::MoveRight(float Distance) {

	this->RelXPos += Distance;
	this->AbsXPos += Distance;

}

void CBase::MoveUp(float Distance) {

	this->RelYPos -= Distance;
	this->AbsYPos -= Distance;


}

void CBase::MoveDown(float Distance) {

	this->RelYPos += Distance;
	this->AbsYPos += Distance;

}

void CBase::Color(int Red, int Green, int Blue) {

	this->RGBRed = Red;
	this->RGBGreen = Green;
	this->RGBBlue = Blue;

}

int CBase::Color(int ConstColor) {

	switch (ConstColor) {
		case RED:
			return this->RGBRed;
		break;
		case GREEN:
			return this->RGBGreen;
		break;
		case BLUE:
			return this->RGBBlue;
		break;

	}

	return 0;

}



Once again, I've tried most every piece of advice I could find before asking. I've tried recreating the entire project thinking that I had done something wrong accidentally in the setup of the project but that didn't fix anything. This is typically an easy error to fix but I can't seem to get ahead of it. It's very possible I'm doing something stupid, but god I hope not. Thanks for your help everyone!
I will forever be a student.
MrAccident
MrAccident
I think I see the problem. On line 40 of CBase.h, you have a closing parenthesis instead of a brace:
	void SetHealth(int HP) { Health = HP; )
Fix that, and I'm guessing your problems will go away.
jrmiller84
jrmiller84
haha, you sir are a godsend. Let me quote myself...

Quote:
It's very possible I'm doing something stupid, but god I hope not.


I knew if another pair of eyes that knows what they're doing looked over it they might find something. Sorry to waste a huge post on something so simple but it was racking my brain all weekend. Thanks a lot!
I will forever be a student.
MrAccident
MrAccident
Heh, don't worry about it. If you knew how many times I've way too long tracking down a problem that wound up being something as silly and mundane as this... And after all these years you'd think I would've learned to check the obvious stuff first. :-X

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.