Archived

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

stefu

Idea to combine source and header files (cpp)

Recommended Posts

stefu    120
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
stefu    120
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
targhan    122
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
petewood    819
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
stefu    120
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