Jump to content
  • Advertisement

Archived

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

stefu

Idea to combine source and header files (cpp)

This topic is 5530 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

Just git an idea flash. Let the code demonstrate
    
#ifndef FILENAME_CPP

#define FILENAME_CPP


#ifdef HEADERS

///////////////////////////////////////////////////////////////////////

// HEADER PART

///////////////////////////////////////////////////////////////////////

class Test {
public:
    void DoTest();
};

#else // HEADERS


///////////////////////////////////////////////////////////////////////

// SOURCE PART

///////////////////////////////////////////////////////////////////////


#define HEADERS

#include "another.cpp"


void Test::DoTest()
{
}

#endif // HEADERS



#endif // FILENAME_CPP


    
Both header and source files are in same file. When HEADERS is undefined, it is used as .cpp file. When HEADERS is defined, it is used as .h file. Bfore these files are included the HEADERS must be defined. What do you think about this? [edited by - stefu on April 30, 2003 8:56:41 AM]

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by petewood
you need to #undef HEADERS after #include "another.cpp"


No, I don''t need to!

Share this post


Link to post
Share on other sites
it''s not a very good idea, and here is why:

whenever you change something in the implementation all files that includes this "header" will have to be recompiled as well.

Share this post


Link to post
Share on other sites
quote:
Original post by stefu
No, I don''t need to!


Okay, I get it.

But... why? It''s a reuse nightmare. It''s against the grain. It''s clunky. It makes all your code visible. You can''t just include a file but have to put #define HEADERS before it. It''s unintuative. It requires everyone to either code their cpp files the same thing way or to know which ones use this unusual quirk. The size of the files will be far bigger than a normal .h and take longer to load into the preprocessor. etc.

Share this post


Link to post
Share on other sites
Hold on, hold on!!!
I am not doing this and not planning, just got idea the idea and asked your opinion.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!