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

C / C++ / MFC

 
AnswerRe: Unicode support Pin
Pandele Florin23-Jun-06 5:09
Pandele Florin23-Jun-06 5:09 
GeneralRe: Unicode support Pin
eusto23-Jun-06 15:00
eusto23-Jun-06 15:00 
QuestionInserting HBitmap object in CRichEditCtrl Pin
Farhat Aisha23-Jun-06 0:12
Farhat Aisha23-Jun-06 0:12 
AnswerRe: Inserting HBitmap object in CRichEditCtrl Pin
Hamid_RT23-Jun-06 0:25
Hamid_RT23-Jun-06 0:25 
QuestionProblem in WH_CBT hook [modified] Pin
Javagal Srinath23-Jun-06 0:03
Javagal Srinath23-Jun-06 0:03 
AnswerRe: Problem in WH_CBT hook Pin
ROWALI23-Jun-06 1:33
ROWALI23-Jun-06 1:33 
QuestionQuestion in basic C++ Pin
LordsAngel22-Jun-06 23:55
LordsAngel22-Jun-06 23:55 
AnswerRe: Question in basic C++ Pin
Cedric Moonen23-Jun-06 0:03
Cedric Moonen23-Jun-06 0:03 
GeneralRe: Question in basic C++ [modified] Pin
Stephen Hewitt23-Jun-06 1:05
Stephen Hewitt23-Jun-06 1:05 
GeneralRe: Question in basic C++ Pin
Emilio Garavaglia23-Jun-06 1:10
Emilio Garavaglia23-Jun-06 1:10 
AnswerRe: Question in basic C++ Pin
Javagal Srinath23-Jun-06 0:16
Javagal Srinath23-Jun-06 0:16 
General[deleted] Pin
toxcct23-Jun-06 0:23
toxcct23-Jun-06 0:23 
GeneralRe: Question in basic C++ Pin
Javagal Srinath23-Jun-06 0:32
Javagal Srinath23-Jun-06 0:32 
General[Message Deleted] Pin
toxcct23-Jun-06 0:37
toxcct23-Jun-06 0:37 
GeneralRe: Question in basic C++ Pin
Javagal Srinath23-Jun-06 1:06
Javagal Srinath23-Jun-06 1:06 
GeneralRe: Question in basic C++ Pin
Stephen Hewitt23-Jun-06 1:14
Stephen Hewitt23-Jun-06 1:14 
GeneralRe: Question in basic C++ Pin
Nish Nishant23-Jun-06 4:50
sitebuilderNish Nishant23-Jun-06 4:50 
AnswerRe: Question in basic C++ Pin
Maximilien23-Jun-06 2:12
Maximilien23-Jun-06 2:12 
GeneralRe: Question in basic C++ Pin
Cedric Moonen23-Jun-06 3:01
Cedric Moonen23-Jun-06 3:01 
AnswerRe: Question in basic C++ Pin
Gary R. Wheeler23-Jun-06 14:58
Gary R. Wheeler23-Jun-06 14:58 
GeneralRe: Question in basic C++ Pin
Stephen Hewitt23-Jun-06 18:58
Stephen Hewitt23-Jun-06 18:58 
There is nothing wrong with initializing a class/struct with memset if you know what you're doing. The basic rule is only use memset on classs/structs which:
 - Don't have any virtual functions.
 - Don't have any virtual base classes.
The above two restrictions are also recursive into the classes members. For example a class itself may not have any virtual functions but some its members may and so it is NOT safe to use memset on it.

While you are correct that "that's what constructors are for" there is little doubt that when it is safe to do so it will be more efficient. Most times the efficiency gain will not be worth it but, as always, there will be exceptions.

If you really want to use memset but still want to use have virtual functions you can do so like this:
struct CMyClass_Data
{
    CMyClass_Data()
    {
       memset(this, 0, sizeof(*this)); // Safe as no virtuals.
    }
 
    // Put members here...
};

class CMyClass : private CMyClass_Data
{
public:
    // Stuff goes here...
 
    virtual VFun1() { /* ... */ }
    virtual VFun2() { /* ... */ }
    // etc...
 
    // Stuff goes here...
}



Steve
GeneralRe: Question in basic C++ Pin
Gary R. Wheeler24-Jun-06 1:04
Gary R. Wheeler24-Jun-06 1:04 
GeneralRe: Question in basic C++ Pin
Stephen Hewitt24-Jun-06 17:32
Stephen Hewitt24-Jun-06 17:32 
GeneralRe: Question in basic C++ Pin
Gary R. Wheeler25-Jun-06 1:54
Gary R. Wheeler25-Jun-06 1:54 
QuestionSending upgrades to client Pin
mohanrajh22-Jun-06 23:50
mohanrajh22-Jun-06 23:50 

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.