Click here to Skip to main content
15,883,458 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
Let's talk first about C where the C++ came from. From the compiler's point of view there is not difference between .h and .cpp files. They are both source files and it treats them identically. By convention (and only by convention) we place declarations in the .h file and code in .cpp one. Also we have to make sure that the compiler sees the code generating lines only once. For instance if you place a function definition:
C++
int my_function () {return 3;}
in a .h file and that file is included by two different .cpp files, the compiler will happily compile them but the linker will complain that it has two instances of the same function and it doesn't know which one to pick.

What we do in this case is to place a function declaration in the .h file:
C++
int my_func ();
Now we can put the function definition in one of the .cpp files and everyone will be happy: the compiler has a declaration for the function so it can check all calls against the function prototype and the linker has only one body for the function.

Now we move to C++. Assume you place this:
C++
class A {
public:
  int func1 ();
  int func2 () {return 2;}
};
in a header file. The member func1 is only declared while the member func2 is also defined. Here the compiler performs a little trick: because the definition of func1 is within the body of a class it tells the linker to use only one instance of the generated code.

If we add a definition for func1 inside the same header file:
C++
class A {
public:
  int func1 ();
  int func2 () {return 2;}
};

int A::func1 () {return 1;}

the compiler will treat it as a regular function and again, if the header is included by two different .cpp file, the linker will complain that the function is doubly defined.

We can do two things now. One is to place an inline specifier in front of the function:
C++
class A {
public:
  int func1 ();
  int func2 () {return 2;}
};

inline int A::func1 () {return 1;}
The compiler will use the same trick as if the function would have been defined inside the body of the class and tell linker to use only one instance.

The other is to simply place the function definition in a .cpp file and in that case the linker will see it only once.

So in the end you have 3 alternatives:
1. place the function definition in the class body.
2. place it in the header file and make it inline.
3. place it in one .cpp file

Which solution you choose depends on your teste and what you want to achieve. The difference between 1 and 2 is purely a question of style (I prefer 2, but that's just me). Number 3 used to be by far the most popular choice until recently when header only libraries have proliferated. It's up to you to decide.
Mircea

AnswerRe: ways to write code for a class Pin
Greg Utas6-Feb-22 10:16
professionalGreg Utas6-Feb-22 10:16 
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 
AnswerRe: C++ Pin
trønderen6-Feb-22 8:00
trønderen6-Feb-22 8:00 
AnswerRe: C++ Pin
Victor Nijegorodov6-Feb-22 8:50
Victor Nijegorodov6-Feb-22 8:50 
AnswerRe: C++ Pin
Artem Moroz8-Feb-22 9:19
Artem Moroz8-Feb-22 9:19 
QuestionRichEdit Streamin SF_TEXT not appearing Pin
ForNow30-Jan-22 14:58
ForNow30-Jan-22 14:58 
AnswerRe: RichEdit Streamin SF_TEXT not appearing Pin
Victor Nijegorodov30-Jan-22 20:43
Victor Nijegorodov30-Jan-22 20:43 
GeneralRe: RichEdit Streamin SF_TEXT not appearing Pin
ForNow30-Jan-22 20:48
ForNow30-Jan-22 20:48 
GeneralRe: RichEdit Streamin SF_TEXT not appearing CODE POSTED !!!!! Pin
ForNow31-Jan-22 1:32
ForNow31-Jan-22 1:32 
GeneralRe: RichEdit Streamin SF_TEXT not appearing CODE POSTED !!!!! Pin
Victor Nijegorodov31-Jan-22 1:45
Victor Nijegorodov31-Jan-22 1:45 
GeneralRe: RichEdit Streamin SF_TEXT not appearing CODE POSTED !!!!! Pin
ForNow31-Jan-22 2:11
ForNow31-Jan-22 2:11 
GeneralRe: RichEdit Streamin SF_TEXT not appearing CODE POSTED !!!!! Pin
Victor Nijegorodov31-Jan-22 2:17
Victor Nijegorodov31-Jan-22 2:17 
GeneralRe: RichEdit Streamin SF_TEXT not appearing CODE POSTED !!!!! Pin
ForNow31-Jan-22 2:31
ForNow31-Jan-22 2:31 
GeneralRe: RichEdit Streamin SF_TEXT not appearing CODE POSTED !!!!! Pin
Victor Nijegorodov31-Jan-22 10:34
Victor Nijegorodov31-Jan-22 10:34 
GeneralRe: RichEdit Streamin SF_TEXT not appearing CODE POSTED !!!!! Pin
ForNow31-Jan-22 10:39
ForNow31-Jan-22 10:39 
GeneralRe: RichEdit Streamin SF_TEXT not appearing CODE POSTED !!!!! Pin
Victor Nijegorodov31-Jan-22 10:52
Victor Nijegorodov31-Jan-22 10:52 

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.