Click here to Skip to main content
15,901,122 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Win7 - worker thread freeze on call to WaitForSingleObject Pin
Stan the man21-Feb-12 1:31
Stan the man21-Feb-12 1:31 
AnswerRe: Win7 - worker thread freeze on call to WaitForSingleObject Pin
bjorn_ht21-Feb-12 1:16
bjorn_ht21-Feb-12 1:16 
AnswerRe: Win7 - worker thread freeze on call to WaitForSingleObject Pin
Erudite_Eric21-Feb-12 2:31
Erudite_Eric21-Feb-12 2:31 
QuestionInitializing base class data Pin
SunilKrSingh20-Feb-12 3:46
SunilKrSingh20-Feb-12 3:46 
AnswerRe: Initializing base class data Pin
prasad_som20-Feb-12 6:49
prasad_som20-Feb-12 6:49 
AnswerRe: Initializing base class data Pin
enhzflep20-Feb-12 14:02
enhzflep20-Feb-12 14:02 
GeneralRe: Initializing base class data Pin
SunilKrSingh20-Feb-12 18:37
SunilKrSingh20-Feb-12 18:37 
GeneralRe: Initializing base class data Pin
enhzflep20-Feb-12 18:53
enhzflep20-Feb-12 18:53 
How about providing a copy constructor in the base class as others have suggested?
Something like so (the displayed output is identical to my previous post):
#include <string.h>
#include <stdio.h>

class Base
{
    public:
         Base(){}
         Base(char * str)
         {
              ptr = new char[strlen(str)+1];
              strcpy(ptr,str);
         }
         Base(const Base &src)
         {
              this->ptr = new char[strlen(src.ptr)+1];
              strcpy(this->ptr,src.ptr);
         }
         virtual void showName()
         {
             printf("%s", ptr);
         }
    private:
        char * ptr;
};

class Derived : public Base
{
    public:
         Derived(char * str1,char * str2):Base(str2)
         {
              ptr_s = new char[strlen(str1)+1];
              strcpy(ptr_s,str1);
         }
         Derived(const Derived & sec):Base(sec)
         {
              printf("Derived(const Derived &sec)\n");
              this->ptr_s = new char[strlen(sec.ptr_s)+1];
              strcpy(this->ptr_s,sec.ptr_s);
         }
        void showName()
        {
            printf("%s", ptr_s);
        }
        void showFullName()
        {
            showName();
            printf(" ");
            Base::showName();
            printf("\n");
        }
    private:
        char * ptr_s;
};

int main(int argc, char* argv[])
{
     Derived Obj1("sunil","singh");

     Derived Obj2 = Obj1;

     Obj1.showFullName();
     Obj2.showFullName();

     return 0;
}

GeneralRe: Initializing base class data Pin
SunilKrSingh20-Feb-12 19:02
SunilKrSingh20-Feb-12 19:02 
QuestionIplImage to Halcon Image Pin
Member 788510519-Feb-12 16:19
Member 788510519-Feb-12 16:19 
AnswerRe: IplImage to Halcon Image Pin
Richard MacCutchan19-Feb-12 22:09
mveRichard MacCutchan19-Feb-12 22:09 
QuestionHOWTO: HH.exe is not listed in taskmgr.exe Pin
cyysoft17-Feb-12 16:14
cyysoft17-Feb-12 16:14 
AnswerRe: HOWTO: HH.exe is not listed in taskmgr.exe Pin
Rajesh R Subramanian17-Feb-12 18:45
professionalRajesh R Subramanian17-Feb-12 18:45 
GeneralRe: HOWTO: HH.exe is not listed in taskmgr.exe Pin
Richard Andrew x6418-Feb-12 10:19
professionalRichard Andrew x6418-Feb-12 10:19 
GeneralRe: HOWTO: HH.exe is not listed in taskmgr.exe Pin
Albert Holguin18-Feb-12 14:27
professionalAlbert Holguin18-Feb-12 14:27 
GeneralRe: HOWTO: HH.exe is not listed in taskmgr.exe Pin
KASR121-Feb-12 6:50
KASR121-Feb-12 6:50 
GeneralRe: HOWTO: HH.exe is not listed in taskmgr.exe Pin
Eddy Vluggen21-Feb-12 8:52
professionalEddy Vluggen21-Feb-12 8:52 
QuestionShare C file across dll boundaries Pin
LionAM17-Feb-12 12:40
LionAM17-Feb-12 12:40 
AnswerRe: Share C file across dll boundaries Pin
Chris Losinger17-Feb-12 18:09
professionalChris Losinger17-Feb-12 18:09 
AnswerRe: Share C file across dll boundaries Pin
Richard MacCutchan17-Feb-12 21:16
mveRichard MacCutchan17-Feb-12 21:16 
GeneralRe: Share C file across dll boundaries Pin
LionAM18-Feb-12 9:44
LionAM18-Feb-12 9:44 
AnswerRe: Share C file across dll boundaries Pin
Albert Holguin18-Feb-12 10:13
professionalAlbert Holguin18-Feb-12 10:13 
GeneralRe: Share C file across dll boundaries Pin
LionAM18-Feb-12 10:38
LionAM18-Feb-12 10:38 
GeneralRe: Share C file across dll boundaries Pin
LionAM18-Feb-12 12:17
LionAM18-Feb-12 12:17 
AnswerRe: Share C file across dll boundaries Pin
Albert Holguin18-Feb-12 14:25
professionalAlbert Holguin18-Feb-12 14:25 

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.