CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: initialise derived class with the base class instance

  1. #1
    Join Date
    May 2015
    Posts
    323

    initialise derived class with the base class instance

    Hello,

    Sorry i removed the code as the code doesnot contain all the info and doesnot compile.

    thanks a lot
    pdk
    Last edited by pdk5; September 22nd, 2020 at 05:11 AM.

  2. #2
    Join Date
    May 2015
    Posts
    323

    Re: initialise derived class with the base class instance

    Btw, i changed to following and it compiles.

    Basically the in the current code, the baseclass is stored in global.

    Now i used the same logic, eventhough i instantiated the derived class, i still copied the base pointer to global. When accessing the gloabl pointer, i checked by dynamic cast to see if it is base or derived.

    I removed the code as it doesnot compile..
    Last edited by pdk5; September 22nd, 2020 at 05:11 AM.

  3. #3
    Join Date
    May 2015
    Posts
    323

    Re: initialise derived class with the base class instance

    It will be very helpful to get some valuable comments , so please help me with comments thankyou very much

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,284

    Re: initialise derived class with the base class instance

    but not giving proper o/p:
    and debugging has indicated that this is because......
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.6)

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,284

    Re: initialise derived class with the base class instance

    Quote Originally Posted by pdk5 View Post
    It will be very helpful to get some valuable comments , so please help me with comments thankyou very much
    When a program compiles OK (no errors and understood and accepted any warnings) but doesn't execute as expected, then you debug the program. You trace through the code, set breakpoints, step though the code line by line, examine the contents of variables etc etc etc until you find the place where the code isn't behaving as expected. Then you have the problem area in the code. Then you examine that part of the code, see what is actually happening as opposed to what was expected to happen, read documentation if required and try to understand why what is happening is happening. Then when you do, you change the code, hopefully to fix the problem, then try it again and debug through the code. If it now works as expected, then great, if it doesn't then either you haven't understood the problem, haven't applied the correct solution or you have another problem. This cycle is repeated until the program works as expected.

    For info, I've worn out the legends of the F9, F10 & F11 keys on at least 3 keyboards over the years using them in VS debugging. Being proficient with the debugger is a skill that all good programmers acquire.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.6)

  6. #6
    Join Date
    May 2015
    Posts
    323

    Re: initialise derived class with the base class instance

    Thankyou very much kaud. I being new joinee here, for my current piece of work, i can only debug in release mode !!! It is because of some restriction of attached thirdparty tool.
    I try to debug in release mode and most of variables are optimised !!. finding it very difficult with this situation

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,284

    Re: initialise derived class with the base class instance

    You can't use the debugger much in release mode - that's what the debug mode is for! However if you can't, you can't.

    Then you have to fall back to what was used before interactive debuggers were invented. Put trace statements in the code (possibly after every line) that output to the console/log file that says where they are and details contents of appropriate variables. If the console, then possibly with keyboard input required after each one. Then when you run the program you either get a log file to examine, or you see what is happening on the screen.

    When I started programming, a long, long time ago....... there was no such thing as 'interactive programming'. Programs were executed as 'batch'. You submitted the program. At some point you got back output from the printer. That's all you had!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.6)

  8. #8
    Join Date
    May 2015
    Posts
    323

    Re: initialise derived class with the base class instance

    Thankyou very much for the inputs and suggestions kaud. Yes, i.e true debugging at that time is very challenging . The suggestions and inputs are really helpful for me to improve.

    I have had some i/p from my collegue and finally with the help, this issue is now in almost getting resolved state,

    thanks a lot for the all the inputs and also being so patient with some of my basic questions.. Very much appreciated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)