Click here to Skip to main content
16,005,206 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralShow unicode control characters in vc++ context menu Pin
inbakumar.G22-Mar-05 1:25
inbakumar.G22-Mar-05 1:25 
QuestionHow to print a clipped area? Pin
Vitaly Tomilov22-Mar-05 1:24
Vitaly Tomilov22-Mar-05 1:24 
Generalbitmap Pin
pravin2922-Mar-05 1:06
pravin2922-Mar-05 1:06 
GeneralRe: bitmap Pin
Iain Clarke, Warrior Programmer22-Mar-05 1:52
Iain Clarke, Warrior Programmer22-Mar-05 1:52 
Generalbasic question to .h and .cpp files Pin
doneirik22-Mar-05 0:47
doneirik22-Mar-05 0:47 
GeneralRe: basic question to .h and .cpp files Pin
KarstenK22-Mar-05 1:13
mveKarstenK22-Mar-05 1:13 
GeneralRe: basic question to .h and .cpp files Pin
Martijn van Kleef22-Mar-05 1:19
Martijn van Kleef22-Mar-05 1:19 
GeneralRe: basic question to .h and .cpp files [edited] Pin
toxcct22-Mar-05 2:09
toxcct22-Mar-05 2:09 
doneirik wrote:
To avoid having to much files...

why would you like to reduce the number of files ? to have only one that is about 80Kb weight ??? Unsure | :~

wow, good luck ! lol

well, in my case, i prefer having several file (one header associated with a module - .cpp), where each module implements a logical section.
Well, you should not be so strict either. For example, if you have a set of functions that are about to represent some Exceptions of your own in your program, you can put them in the same file, including also the functions implementation if they are writing on few lines.
Of course, this is a suggestion, you can do whatever you like, but i also think that if most of experienced programmers separate the actual instructions from declarations, they do have some reasons...

doneirik wrote:
Do the compiler treat code in the .h file differenly?
actually, .h files are not compiled. The #include directive tells the pre-processor to copy the content of the .h file where such instruction is written in a file.

doneirik wrote:
Is there code that cannot be written in the header file?
Yep, affirmative !!

A header can contain :
- named namespaces (namespace N { /*...*/ });
- Types definitions (struct Point { int x, y; };)
- Templates declarations (template<class T> class Z;)
- Templates definitions (template<class T> class V { /*...*/ };)
- Functions declarations (extern int strlen(const char*);)
- inline functions definitions (inline char get(char* p) { return *p++; })
- Datas declarations (extern int a;)
- Constants definitions (const float pi = 3.141593;)
- Enumerations (enum Light { red, yellow, green };)
- Names declarations (class Matrix)
- Inclusion directives (#include <algorithm>)
- Macros definitions (#define VERSION 12)
- Conditional compilation directives (#ifdef _cplusplus)
- Comments (/* End of file */)

In the other hand, a header might never contain :
- Ordinary functions definitions (char get(char* p) { return *p++; })
- Datas definitions (int a)
- Arrays definitions (short tbl[] = {1, 2, 3};)
- Non-named namespaces (namespace { /*...*/ })
- Exported templates definitions (export template<class T> f(T t) { /*...*/ })

Moreover, Mr Stroustrup tells us in it famous book "The C++ Language" the following advices :
- Use headers to represent interfaces and to emphasize the logical structure;
- A header file must be included in a source file that implements its functions;
- Do not define global entities with the same name but not the same meaning within different units of translation (.cpp source files);
- Avoid writing non-inline function definitions inside headers;
- Use #include directive only in global scope and in namespaces;
- Never include incomplete declarations;
- Use made safe inclusions;
- Include C headers inside namespaces to avoid global names;
- Headers should be autonomous
- You may distinguish user interfaces from implementation functions interfaces;
- You may distinguish average users' interfaces from expert users' interfaces;
- Avoid non-local objects that need to be initialised with the execution, when the code have to be included in a program written in another language.

cheers,


TOXCCT >>> GEII power
[toxcct][VisualCalc]
GeneralRe: basic question to .h and .cpp files Pin
Nitron22-Mar-05 2:35
Nitron22-Mar-05 2:35 
GeneralUsing CreateDialogIndirect Pin
kedar.dave22-Mar-05 0:46
kedar.dave22-Mar-05 0:46 
GeneralRe: Using CreateDialogIndirect Pin
Mircea Puiu22-Mar-05 4:23
Mircea Puiu22-Mar-05 4:23 
GeneralSetDICreateDeviceInfoList() Pin
brilliant10122-Mar-05 0:42
brilliant10122-Mar-05 0:42 
GeneralRe: SetDICreateDeviceInfoList() Pin
brilliant10122-Mar-05 0:45
brilliant10122-Mar-05 0:45 
GeneralRe: SetDICreateDeviceInfoList() Pin
David Crow22-Mar-05 2:17
David Crow22-Mar-05 2:17 
QuestionHow to get text on screen Pin
levgiang22-Mar-05 0:41
levgiang22-Mar-05 0:41 
AnswerRe: How to get text on screen Pin
jan larsen22-Mar-05 1:25
jan larsen22-Mar-05 1:25 
AnswerRe: How to get text on screen Pin
Anand for every one22-Mar-05 1:30
Anand for every one22-Mar-05 1:30 
AnswerRe: How to get text on screen Pin
David Crow22-Mar-05 2:20
David Crow22-Mar-05 2:20 
GeneralRe: How to get text on screen Pin
Anonymous22-Mar-05 23:30
Anonymous22-Mar-05 23:30 
GeneralRe: How to get text on screen Pin
David Crow23-Mar-05 3:07
David Crow23-Mar-05 3:07 
Generalnamespace does not exist Pin
doneirik22-Mar-05 0:40
doneirik22-Mar-05 0:40 
GeneralRe: namespace does not exist Pin
Martijn van Kleef22-Mar-05 1:11
Martijn van Kleef22-Mar-05 1:11 
GeneralRe: namespace does not exist Pin
toxcct22-Mar-05 1:41
toxcct22-Mar-05 1:41 
GeneralRe: namespace does not exist Pin
CP Visitor22-Mar-05 4:17
CP Visitor22-Mar-05 4:17 
Questionhow to maintain text file constant Pin
shaans22-Mar-05 0:39
shaans22-Mar-05 0:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.