Hi gray!<br>
<br>
I put all the implentations of my class functions into the same .cpp file. I suppose you could split them up, but it might make it harder to find them later when you're maintaining your app.<br>
<br>
I don't know if you've seen this trick, but in the header file, you surround it with precompiler statements so that it doesn't get included twice. I also include all the standard (lowercase) include files in there, surrounded by precompiler statements as well. This ensures that if I include the header in another .cpp file, and headers that are needed are included too.<br>
<br>
example:<br>
//---My.cpp<br>
#define __MY_DEF__<br>
#include "my.h"<br>
{class implementation}<br>
<br>
<br>
//---My.h<br>
#ifndef __MY_H__<br>
#define __MY_H__<br>
<br>
// Only include these if they haven't been before<br>
#ifndef _IOSTREAM_<br>
#include <iostream><br>
#endif<br>
<br>
#ifndef _DEQUE_<br>
#include <deque><br>
#endif<br>
<br>
{define my class here}<br>
<br>
#ifdef __MY_DEF__<br>
{variables, etc. whose scope should be limited to my.cpp}<br>
#else<br>
{variables, etc. whose scope should be public}<br>
#endif<br>
#endif<br>
<br>
<br>
You can also use the #PRAGMA ONCE to prevent double-includes, but I think it's specific to Microsoft's VC++.<br>
<br>
Chip H.<br>
Best to put definitions into a .cpp. The class should be a general declaration of what variables and functions are available. The .cpp defines those variables and functions as to specifically how they will be used. Keeps it clearer.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.