multiple definition of Character.getName()

Pages: 12
I deleted the .H off all my #ifndef and #define lines, and now the warnings are gone. The 37 errors are still there....
Last edited on
Current errors:

||=== Build: Debug in myFantasy (compiler: GNU GCC Compiler) ===|
obj/Debug/character.o||In function `Character::getName()':|
/home/michael/projects/codeblocks/character.cpp|4|multiple definition of `Character::getName()'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|4|first defined here|
obj/Debug/character.o||In function `Character::setName(std::string)':|
/home/michael/projects/codeblocks/character.cpp|5|multiple definition of `Character::setName(std::string)'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|5|first defined here|
obj/Debug/character.o||In function `Character::getCurHP()':|
/home/michael/projects/codeblocks/character.cpp|7|multiple definition of `Character::getCurHP()'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|7|first defined here|
obj/Debug/character.o||In function `Character::setCurHP(int)':|
/home/michael/projects/codeblocks/character.cpp|8|multiple definition of `Character::setCurHP(int)'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|8|first defined here|
obj/Debug/character.o||In function `Character::getCurMP()':|
/home/michael/projects/codeblocks/character.cpp|10|multiple definition of `Character::getCurMP()'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|10|first defined here|
obj/Debug/character.o||In function `Character::setCurMP(int)':|
/home/michael/projects/codeblocks/character.cpp|11|multiple definition of `Character::setCurMP(int)'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|11|first defined here|
obj/Debug/character.o||In function `Character::getMaxHP()':|
/home/michael/projects/codeblocks/character.cpp|13|multiple definition of `Character::getMaxHP()'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|13|first defined here|
obj/Debug/character.o||In function `Character::setMaxHP(int)':|
/home/michael/projects/codeblocks/character.cpp|14|multiple definition of `Character::setMaxHP(int)'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|14|first defined here|
obj/Debug/character.o||In function `Character::getMaxMP()':|
/home/michael/projects/codeblocks/character.cpp|16|multiple definition of `Character::getMaxMP()'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|16|first defined here|
obj/Debug/character.o||In function `Character::setMaxMP(int)':|
/home/michael/projects/codeblocks/character.cpp|17|multiple definition of `Character::setMaxMP(int)'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|17|first defined here|
obj/Debug/character.o||In function `Character::getIMFileName()':|
/home/michael/projects/codeblocks/character.cpp|19|multiple definition of `Character::getIMFileName()'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|19|first defined here|
obj/Debug/character.o||In function `Character::setIMFileName(std::string)':|
/home/michael/projects/codeblocks/character.cpp|20|multiple definition of `Character::setIMFileName(std::string)'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|20|first defined here|
obj/Debug/character.o||In function `Character::getX()':|
/home/michael/projects/codeblocks/character.cpp|22|multiple definition of `Character::getX()'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|22|first defined here|
obj/Debug/character.o||In function `Character::setX(int)':|
/home/michael/projects/codeblocks/character.cpp|23|multiple definition of `Character::setX(int)'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|23|first defined here|
obj/Debug/character.o||In function `Character::getY()':|
/home/michael/projects/codeblocks/character.cpp|25|multiple definition of `Character::getY()'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|25|first defined here|
obj/Debug/character.o||In function `Character::setY(int)':|
/home/michael/projects/codeblocks/character.cpp|26|multiple definition of `Character::setY(int)'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|26|first defined here|
obj/Debug/character.o||In function `Character::getCurImage()':|
/home/michael/projects/codeblocks/character.cpp|28|multiple definition of `Character::getCurImage()'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|28|first defined here|
obj/Debug/character.o||In function `Character::setCurImage(int)':|
/home/michael/projects/codeblocks/character.cpp|29|multiple definition of `Character::setCurImage(int)'|
obj/Debug/character.o:/home/michael/projects/codeblocks/character.cpp|29|first defined here|
||error: ld returned 1 exit status|
||=== Build failed: 37 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Current character.h:

[code]
#ifndef CHARACTER
#define CHARACTER
#include <string>
using namespace std;

class Character
{
private:
string name;
int curHP;
int curMP;

int maxHP;
int maxMP;

int xPos;
int yPos;

string imageMapFileName;

int curImage;

public:
//Character(void);
//~Character(void);

string getName();
void setName(string n);

int getCurHP();
void setCurHP(int hp);

int getCurMP();
void setCurMP(int mp);

int getMaxHP();
void setMaxHP(int hp);

int getMaxMP();
void setMaxMP(int m);

string getIMFileName();
void setIMFileName(string fn);

int getX();
void setX(int x);

int getY();
void setY(int y);

int getCurImage();
void setCurImage (int ci);
};
#endif // CHARACTER
[/code[
Last edited on
Current character.cpp:

#include "character.h"
using namespace std;

string Character::getName() {return name; }
void Character::setName(string name) {this->name = name;}

int Character::getCurHP() {return this->curHP; }
void Character::setCurHP(int hp) {this->curHP = hp; }

int Character::getCurMP() {return this->curMP; }
void Character::setCurMP(int mp) {this->curMP = mp; }

int Character::getMaxHP() {return this->maxHP; }
void Character::setMaxHP(int hp) {this->maxHP = hp;}

int Character::getMaxMP() {return this->maxMP; }
void Character::setMaxMP(int m) {this->maxMP = m; }

string Character::getIMFileName() { return this->imageMapFileName; }
void Character::setIMFileName(string fn) { this->imageMapFileName = fn; }

int Character::getX() {return xPos; }
void Character::setX(int x) {this->xPos = x; }

int Character::getY() { return this->yPos; }
void Character::setY(int y) {this->yPos = y; }

int Character::getCurImage() {return curImage;}
void Character::setCurImage (int ci) {this->curImage = ci; }
I apologize. Of course you're correct that that date I posted was NOT character.h. I've corrected the posting. It is now character.h. Sometimes I don't take the time to fully examine the data I post. It's a process I'm trying to work through. Each one of us learns at different speeds. At my age it is easier to assume that someone else is wrong and I am right. This behaviour is one of several that I am desperately trying to change in myself. Know that I AM trying.

Thank you again for trying to help me reach my goals, or at least to take a step forward...
Last edited on
I added a new class Character to the Code::Blocks project. The IDE added new files Character.h and Character.cpp to the poject. I copy/pasted the code from character.h to Character.h. I've gone through all my files and changed all occurrences of character.h to Character.h. When I try to build, it reports that it can't find Character.h:

/home/michael/projects/codeblocks/party.h|3|fatal error: Character.h: No such file or directory|

party.h:

#ifndef PARTY
#define PARTY
#include "Character.h"


class Party
{
public:
Party(void);
~Party(void);
virtual bool Include() = 0;
void Exclude(Character character);
virtual Character* getCharacter(int i) = 0;
int getCount();
protected:
int count;
};
#endif
Last edited on
I looked in the Code::Blocks Project->Properties and it says that my project is stored in /home/michael/projects/codeblocks/myFantasy/myFantasy.cbp. I think that would make the CWD ~/projects/codeblocks/myFantasy, correct? There is a Character.h file in ~/projects/codeblocks/src above and to the side of my CWD. How would I alter my #include to find it? I tried ~/projects/codeblocks/src in party.h, but it didn't work. As I believe I said earlier, this is my first time using Code::Blocks. I guess I should seach Google for a crash course...
Topic archived. No new replies allowed.
Pages: 12