Problems with classes and headers :/

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
DarkPhoenix
Posts: 3
Joined: June 4th, 2012, 4:40 pm

Problems with classes and headers :/

Post by DarkPhoenix » June 4th, 2012, 4:45 pm

Sorry to just join the forum and already bring up an issue I'm having but, Visual Studio keeps saying that my functions are already declared/defined and it errors.... I've been reading on this for the past... weeks now... can someone tell/show me what I'm doing wrong here? Thank you in advance!

~ DarkPhoenix
Attachments
TextRPG.zip
TextRPG
(1.73 MiB) Downloaded 199 times

DarkPhoenix
Posts: 3
Joined: June 4th, 2012, 4:40 pm

Re: Problems with classes and headers :/

Post by DarkPhoenix » June 4th, 2012, 6:45 pm

If you don't want to download anything, here's the code that's giving me issues mostly:

Level.h

Code: Select all

#ifndef LEVEL_H
#define LEVEL_H

class Level
{
private:
	int level;
	int exp;
	int tnl;
	int tempexp;

public:
	Level();
	int getLevel() {return level;}
	void setLevel(int);
	int getExp() {return exp;}
	void setExp(int);
	int getTNL() {return tnl;}
	void setTNL(int);
	int getTemp() {return tempexp;}
	void setTemp(int);
	void levelUp(int,int,int,int);

#endif
Level.cpp

Code: Select all

#include "Level.h"

Level::Level()
:
		level ( 1 ),
		exp ( 0 ),
		tnl ( 325 ),
		tempexp ( 0 )
{}

void Level::setLevel(int l)
{
	level = l;
}

void Level::setExp(int e)
{
	exp = e;
}

void Level::setTNL(int t)
{
	tnl = t;
}

void Level::setTemp(int temp)
{
	tempexp = temp;
}

void Level::levelUp(int l, int e, int t, int temp)
{
	if (temp > 0)
	{
		setExp(getExp() + temp);
		setTemp(0);
		if (e => t)
		{
			setLevel(getLevel() + 1);
			tnl = t - e;
			setTNL(((getLevel() * 100) + 1200) / 4);
		}
	}
}
Thanks again xD

~ DarkPhoenix

uglypie
Posts: 21
Joined: May 5th, 2012, 5:05 pm

Re: Problems with classes and headers :/

Post by uglypie » June 4th, 2012, 8:27 pm

You're missing a curly brace (and semicolon) after the class declaration. The begin class also lacks a semicolon after the curly brace.

These kinds of errors are often difficult to find, because the error often shows up in a different file.

DarkPhoenix
Posts: 3
Joined: June 4th, 2012, 4:40 pm

Re: Problems with classes and headers :/

Post by DarkPhoenix » June 4th, 2012, 8:49 pm

..... Completely forgot about that closing brace because I jumped into the .cpp after I finished the declaration >_>.... Thank you xD

~ DarkPhoenix

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Problems with classes and headers :/

Post by chili » June 5th, 2012, 12:10 am

Hey uglypie, long time no see! :lol:

Thanks for answering this one bro. 8-)
Chili

Post Reply