Programming Tips 8
 

Programming Tips 1

 

Programming Tips 2

 

Programming Tips 3

 

Programming Tips 4


Programming Tips 5


Programming Tips 6

 

Programming Tips 7

 

Programming Tips 8

  

Programming Tips 9 

C Tip


On including a file twice I get errors reportingredefinition of function. How can I avoid duplicate inclusion?

Ans: Redefinition errors can be avoided by using the following macro definition. Include this definition in the header file.

#if !defined filename_h

#define filename_h

/* function definitions */

#endif

Replace filename_h with the actual header file name. For example, if name of file to be included is 'goto.h' then replace filename_h with 'goto_h'.



C++ Tip


Why can't data members of a class be initialized at the time of declaration as given in the following code?

class emp

{

private :

int j = 10 ;

} ;

Ans: Memory for data members of a class is allocated only when object of that class is created. One cannot store data in a memory location which does not exist at all. Therefore initialization at the time of declaration is not possible.



VC++ Tip


How would you remove 'Untitled' from caption bar in Doc/View?

Ans: To remove 'Untitled' from caption bar of frame window in Doc/View add following code.

int PreCreateWindow ( CREATESTRUCT cs )
{

cs.style &= ~FWS_ADDTOTITLE ;

return CFrameWnd::PreCreateWindow ( cs ) ;

}