![]() |
|
#1
|
|||
|
|||
Multiple files and includes help!Started a little project in C++ and i'm using OOP with multiple files and classes, though I know how to use OOP I don't fully know how to use the multiple file system C++ incorporates in order to stop creating errors every 5 seconds.
When I compile I get these errors: Error 1 error LNK2005: "char __cdecl input_letter(char,char)" (?input_letter@@YADDD@Z) already defined in Main.obj validate_verify.obj Error 2 error LNK2005: "public: __thiscall Entity::Entity(void)" (??0Entity@@QAE@XZ) already defined in Main.obj entity.obj Error 3 error LNK2005: "public: __thiscall Monster::Monster(void)" (??0Monster@@QAE@XZ) already defined in Main.obj monster.obj Error 4 error LNK2005: "public: __thiscall Player::Player(void)" (??0Player@@QAE@XZ) already defined in Main.obj player.obj Error 5 error LNK2005: "public: void __thiscall Player::setName(void)" (?setName@Player@@QAEXXZ) already defined in Main.obj player.obj Error 6 error LNK2019: unresolved external symbol "public: __thiscall Entity::~Entity(void)" (??1Entity@@QAE@XZ) referenced in function __unwindfunclet$??0Player@@QAE@XZ$0 Main.obj Error 7 error LNK2001: unresolved external symbol "public: __thiscall Entity::~Entity(void)" (??1Entity@@QAE@XZ) player.obj Right, I've got 10 files, 5 cpp files for each of my objects and other classes, and their corresponding header files: main.h CPP / C++ / C Code:
Main.cpp CPP / C++ / C Code:
validate_verify.h CPP / C++ / C Code:
validate_verify.cpp CPP / C++ / C Code:
entity.h CPP / C++ / C Code:
Entity.cpp CPP / C++ / C Code:
player.h CPP / C++ / C Code:
Player.cpp CPP / C++ / C Code:
monster.h CPP / C++ / C Code:
Monster.cpp CPP / C++ / C Code:
Entity is the super-class of Human and Monster in my Hierarchy, and I need to access validate_verify from every file. If you can tell me what files I have to link to and what not to that would help me tremendously! |
|||
|
#2
|
|||
|
|||
Re: Multiple files and includes help!Quote:
In main.h: don't (that's do not) include any of your cpp files. As a matter of fact I wouldn't have a main.h anyhow. Just include whatever header files you need in main.cpp. Furthermore: There is no good reason to have the inclusion guards in any cpp files. If you do as I suggest, you really won't need them. (And as you found out, they don't do any good there anyhow.) If you are compiling from a command line, you can compile them one at a time (with the "-c" compile option), and then compile all of the object files together. By compiling one at a time, you can fix syntax and other "obvious" errors as you go. Or... You can simply compile all together on the command line. If you are using an Integrated Development Environment, just put all of the files in your project and compile. Regards, Dave |
|
#3
|
|||
|
|||
Re: Multiple files and includes help!Okay i've removed the inclusion guards from the .cpp files, removed the main.h and put the libraries and includes back into main.cpp and changed them to look at the header files.
It woks now as I also added the destructor for Entity in Entity.cpp, thanks for you help! |
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error compiling Apache 2.2.10 | tiagofgarcia | Apache Web Server Forum | 2 | 10-Nov-2009 13:31 |
| Named virtual host not working | Johnnyrotton | Apache Web Server Forum | 4 | 04-Sep-2007 20:32 |
| me use gcc and feel problems | u04f061 | C Programming Language | 6 | 18-Aug-2006 15:19 |
| Apache2 config issues | monev | Apache Web Server Forum | 2 | 28-Jun-2004 06:19 |
| Can't view pages from another machine on the Intranet | aevans | Apache Web Server Forum | 9 | 14-May-2004 02:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The