Click here to Skip to main content
15,902,276 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
AnswerRe: Sending upgrades to client Pin
Cedric Moonen22-Jun-06 23:55
Cedric Moonen22-Jun-06 23:55 
QuestionInstalling font [modified] Pin
<color>Aljechin 22-Jun-06 23:46
<color>Aljechin 22-Jun-06 23:46 
AnswerRe: Installing font Pin
Hamid_RT22-Jun-06 23:56
Hamid_RT22-Jun-06 23:56 
AnswerRe: Installing font Pin
David Crow23-Jun-06 3:05
David Crow23-Jun-06 3:05 
QuestionBeginner:how to map a key input? Pin
zouchao111222-Jun-06 23:45
zouchao111222-Jun-06 23:45 
AnswerRe: Beginner:how to map a key input? Pin
eusto23-Jun-06 0:48
eusto23-Jun-06 0:48 
QuestionRe: Beginner:how to map a key input? Pin
David Crow23-Jun-06 3:08
David Crow23-Jun-06 3:08 
QuestionSave file to ftp Pin
bahamutnice22-Jun-06 23:19
bahamutnice22-Jun-06 23:19 
AnswerRe: Save file to ftp Pin
Ștefan-Mihai MOGA23-Jun-06 1:06
professionalȘtefan-Mihai MOGA23-Jun-06 1:06 
AnswerRe: Save file to ftp Pin
Ștefan-Mihai MOGA23-Jun-06 1:12
professionalȘtefan-Mihai MOGA23-Jun-06 1:12 
Questionadding a form Pin
Desmo1622-Jun-06 23:16
Desmo1622-Jun-06 23:16 
AnswerRe: adding a form Pin
_AnsHUMAN_ 22-Jun-06 23:40
_AnsHUMAN_ 22-Jun-06 23:40 
QuestionProperty sheet Pin
sujtha22-Jun-06 22:57
sujtha22-Jun-06 22:57 

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.