sending a class address to a new function..

first, hello all. err... was gonna say more on the lines of hello but i forgot... that quick... sad...

moving on.

so here's my problem.

Attack( &Main, &enemy );&&

1
2
3
4
5
6
7
int Attack( Character * attacker, Character * defender )
{
    std::cout << std::endl;
    std::cout << "attacker strength: " << attacker->GetStr() << std::endl;
    std::cout << "defender defence: " << defender->GetDef() << std::endl;
    return 0;
}
produces...

------ Build started: Project: Text based test rpg, Configuration: Debug Win32 ------
Linking...
BattleSystem.obj : error LNK2005: "public: __thiscall Character::Character(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,int,int,int,int)" (??0Character@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHHHH@Z) already defined in main.obj
BattleSystem.obj : error LNK2005: "public: __thiscall Character::Character(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,int,int,int,int,int,int)" (??0Character@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHHHHHH@Z) already defined in main.obj
D:\My Documents\Visual Studio 2008\Projects\RPG\Debug\Text based test rpg.exe : fatal error LNK1169: one or more multiply defined symbols found
Build log was saved at "file://d:\My Documents\Visual Studio 2008\Projects\RPG\Text based test rpg\Debug\BuildLog.htm"
Text based test rpg - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
im using visual studios, and the problem is that in main, i call Attack() and pass on the address of 2 classes.

however, it wont compile, linker errors... the ones that are confusing...

i think that whats happening is that the attack function, or this part of it anyway...
"int Attack( Character * attacker, Character * defender )"
attempts to create already existing class object or something...

so is there a way to pass an address of a class on to a function without getting an error? i really don't feel like gathering the data from the classes and passing that on for my method to work with... to un-organized.

here is the full source if anymore info is needed.

http://www.mediafire.com/?knfynznwa0m

thanks in advance..
i really didn't expect this error. :s


EDIT:

is there a way to subscribe to topics on this forum... not seeing a button. (still looking)
Last edited on
Have two source files, main.cpp and BattleSystem.cpp, that have compiled copies of two constructors for class Character.

Do you have the source code for these constructors in a header file that is not inline?
i supplied the full source to the project here (its very incomplete as i just started working on it....)

http://www.mediafire.com/?knfynznwa0m

i have the entire class, and all its methods(functions), in Character.h header file.
included in both main.cpp and BattleSystem.cpp

EDIT:

wtf...

ok well i fixed it, i moved the constructor method into main.cpp and now it links.

thats odd... but w/e
really suck tho cause i would like to be able to group related stuff like that into one single file.
Last edited on
i have the entire class, and all its methods(functions), in Character.h header file.
included in both main.cpp and BattleSystem.cpp


^^That's your problem right there
Topic archived. No new replies allowed.