Archived

This topic is now archived and is closed to further replies.

Best way to work with multiple files?

This topic is 5621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I like to use many cpp files especially for the better overview and because it''s easier to find back all "input" functions if I put them together in an input.cpp file. But doing so brings the fact that I need to use header files, and with that comes the "multiple definition error". So basicly if I don''t use header files, the different cpp files can''t reach each other''s functions, but if I do use header files and include them everywhere, I get multiple defenition errors. In my previous project I got around it in a way that''s not so clean I think and I want to do it good this time. So what must I do to do this in a clean way?

Share this post


Link to post
Share on other sites
in your header files, place a

#ifndef HEADER_FILENAME_H
#define HEADER_FILENAME_H

// ...
// declarations
// ...
#endif

That way, when your header file is called several times from other CPP files, the compiler will know it''s already defined and use the stuff from the originating header file.

There are other methods also but I"m limited on time right now.

Do a search on "multiple definition error". You''re not the first to encounter this problem here.

Later.

Share this post


Link to post
Share on other sites
I don't understand! I add these lines to the header file, but I still get the multiple definition error. I'm using Dev-c++, is that one ignoring #ifndef's or something?

[edit] never mind I got it, I shouldn't define variables in header files.

[edited by - Lode on July 24, 2002 4:34:01 PM]

Share this post


Link to post
Share on other sites