Archived

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

stefu

Idea to combine source and header files (cpp)

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
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