Click here to Skip to main content
15,917,328 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C Pin
Greg Utas26-Feb-22 10:32
professionalGreg Utas26-Feb-22 10:32 
Questionhow to dynamically delete sub-control created in run-time Pin
wuxianzhong18-Feb-22 15:54
wuxianzhong18-Feb-22 15:54 
AnswerRe: how to dynamically delete sub-control created in run-time Pin
Gerry Schmitz18-Feb-22 20:30
mveGerry Schmitz18-Feb-22 20:30 
AnswerRe: how to dynamically delete sub-control created in run-time Pin
Victor Nijegorodov18-Feb-22 21:18
Victor Nijegorodov18-Feb-22 21:18 
AnswerRe: how to dynamically delete sub-control created in run-time Pin
Randor 19-Feb-22 6:27
professional Randor 19-Feb-22 6:27 
QuestionAzure DevOps Chocolatey question : install vs2022 Pin
Maximilien17-Feb-22 7:52
Maximilien17-Feb-22 7:52 
AnswerRe: Azure DevOps Chocolatey question : install vs2022 Pin
Mircea Neacsu17-Feb-22 8:02
Mircea Neacsu17-Feb-22 8:02 
GeneralRe: Azure DevOps Chocolatey question : install vs2022 Pin
Maximilien18-Feb-22 3:23
Maximilien18-Feb-22 3:23 
GeneralRe: Azure DevOps Chocolatey question : install vs2022 Pin
Mircea Neacsu18-Feb-22 5:06
Mircea Neacsu18-Feb-22 5:06 
QuestionMessage Closed Pin
13-Feb-22 18:51
Member 1496877113-Feb-22 18:51 
AnswerRe: resource wanted - print control / color codes Pin
Gerry Schmitz13-Feb-22 19:32
mveGerry Schmitz13-Feb-22 19:32 
AnswerRe: resource wanted - print control / color codes Pin
Richard MacCutchan13-Feb-22 22:24
mveRichard MacCutchan13-Feb-22 22:24 
AnswerRe: resource wanted - print control / color codes Pin
Peter_in_278013-Feb-22 22:31
professionalPeter_in_278013-Feb-22 22:31 
QuestionStatic OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
ForNow7-Feb-22 14:53
ForNow7-Feb-22 14:53 
AnswerRe: Static OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
Richard MacCutchan7-Feb-22 21:08
mveRichard MacCutchan7-Feb-22 21:08 
GeneralRe: Static OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
Victor Nijegorodov7-Feb-22 22:49
Victor Nijegorodov7-Feb-22 22:49 
GeneralRe: Static OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
Richard MacCutchan7-Feb-22 23:39
mveRichard MacCutchan7-Feb-22 23:39 
AnswerRe: Static OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
Victor Nijegorodov7-Feb-22 22:42
Victor Nijegorodov7-Feb-22 22:42 
GeneralRe: Static OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
ForNow8-Feb-22 1:23
ForNow8-Feb-22 1:23 
GeneralRe: It gets called at the end of the OnInitDialog Pin
ForNow8-Feb-22 11:25
ForNow8-Feb-22 11:25 
Questionways to write code for a class Pin
Calin Negru6-Feb-22 7:43
Calin Negru6-Feb-22 7:43 
AnswerRe: ways to write code for a class Pin
Mircea Neacsu6-Feb-22 9:15
Mircea Neacsu6-Feb-22 9:15 
AnswerRe: ways to write code for a class Pin
Greg Utas6-Feb-22 10:16
professionalGreg Utas6-Feb-22 10:16 
To add to what Mircea said, function definitions (implementations) usually go in a .cpp for two reasons:
  1. By default, a header is recompiled each time that a .cpp #includes it, so defining large functions in headers can really slow down a compile. Some compilers optimize this, but it isn't guaranteed.
  2. A header should be an interface, with implementation details going in a .cpp rather than cluttering the header.
However, there are two situations when function definitions go in a header:
  1. If a function is simple, usually just a single line, it's expedient to just define it in the header.
  2. A function template, or a function in a class template, is defined in a header.
As far as where to define functions is concerned, I prefer to define each class in its own header (Class.h) and implement its functions in Class.cpp. This isn't mandatory, because the .h and .cpp are not compiled into a single binary. Each .cpp, along with all the headers that it #includes, is compiled into its own binary, after which the linker merges them all.

Some C++ gurus say there is no rationale for putting each class in its own .h and .cpp. They're wrong, but there are exceptions:
  1. A "helper" class (used only to implement another one) can be defined in the same .cpp as the only class that uses it.
  2. Small, related classes can be defined in a common .h and implemented in a common .cpp.
However, each important class gets its own .h and .cpp. This makes code easy to find, even outside the IDE. Besides, anything else is arbitrary; no one would suggest that one big .cpp is good for a project with 10,000+ lines of code. Some kind of organization is needed, and the approach that I've described is the obvious one.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.

GeneralRe: ways to write code for a class Pin
Calin Negru6-Feb-22 23:28
Calin Negru6-Feb-22 23:28 
QuestionC++ Pin
Naveenkumarreddy Ramireddy6-Feb-22 6:44
Naveenkumarreddy Ramireddy6-Feb-22 6:44 

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.