Click here to Skip to main content
15,892,537 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWin7 - worker thread freeze on call to WaitForSingleObject Pin
Stan the man21-Feb-12 0:12
Stan the man21-Feb-12 0:12 
AnswerRe: Win7 - worker thread freeze on call to WaitForSingleObject Pin
Jochen Arndt21-Feb-12 0:29
professionalJochen Arndt21-Feb-12 0:29 
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 
Does this do what you want?
I:
1) Added +1 to all of the strlen statements used for memory allocation (strlen doesn't account for the NULL terminator - which you need to allow for when storing the string, as opposed to simply displaying it)
2) Made the data members protected
3) Uncommented the call to the Base constructor in the 2nd constructor for Derived

Code:
C++
#include <string.h>
#include <stdio.h>

class Base
{
    public:
         Base(){}
         Base(char * str)
         {
              ptr = new char[strlen(str)+1];
              strcpy(ptr,str);
         }
    protected:
        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.ptr)
         {
              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 %s\n", ptr_s, ptr);
        }
    protected:
        char * ptr_s;
};

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

     Derived Obj2 = Obj1;

     Obj1.showName();
     Obj2.showName();

     return 0;
}


Result:
Derived(const Derived &sec)
sunil singh
sunil singh

Process returned 0 (0x0) execution time : 0.055 s
Press any key to continue.
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 
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 

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.