Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem Initialising derived class

Problem Initialising derived class

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingoophelp
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Still learning how to code
    wrote on last edited by
    #1

    I am very new to putting inheritance into practice, so please treat me gently ! I am trying to create a new class CTimeEx to provide extra functions to CTime. The problem is that from the client’s point of view, the derived class doesn’t seem to be initialised. My derived class definition is :- class CTimeEx : public CTime { public: CTimeEx(); CTimeEx(const CTime& TimeIn) : CTime(TimeIn) {}; …. And my client invocation is :- CTime timeCurrent(CTime::GetCurrentTime()); CTimeEx timeExTest(timeCurrent); When I trace through the calls, I see the base class contructor being called with timeCurrent, but when initialisation of the derived class completes, the time value for the CTimeEx object is still in it’s uninitialised state. I’m sure that I’m probably doing something very stupid, but, having struggled with it for quite some time, I now need someone elses advice !! Thanking you in advance ! Doug

    C L 2 Replies Last reply
    0
    • S Still learning how to code

      I am very new to putting inheritance into practice, so please treat me gently ! I am trying to create a new class CTimeEx to provide extra functions to CTime. The problem is that from the client’s point of view, the derived class doesn’t seem to be initialised. My derived class definition is :- class CTimeEx : public CTime { public: CTimeEx(); CTimeEx(const CTime& TimeIn) : CTime(TimeIn) {}; …. And my client invocation is :- CTime timeCurrent(CTime::GetCurrentTime()); CTimeEx timeExTest(timeCurrent); When I trace through the calls, I see the base class contructor being called with timeCurrent, but when initialisation of the derived class completes, the time value for the CTimeEx object is still in it’s uninitialised state. I’m sure that I’m probably doing something very stupid, but, having struggled with it for quite some time, I now need someone elses advice !! Thanking you in advance ! Doug

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Could you please post the complete code of your class, using the 'code block' button?

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      S 1 Reply Last reply
      0
      • S Still learning how to code

        I am very new to putting inheritance into practice, so please treat me gently ! I am trying to create a new class CTimeEx to provide extra functions to CTime. The problem is that from the client’s point of view, the derived class doesn’t seem to be initialised. My derived class definition is :- class CTimeEx : public CTime { public: CTimeEx(); CTimeEx(const CTime& TimeIn) : CTime(TimeIn) {}; …. And my client invocation is :- CTime timeCurrent(CTime::GetCurrentTime()); CTimeEx timeExTest(timeCurrent); When I trace through the calls, I see the base class contructor being called with timeCurrent, but when initialisation of the derived class completes, the time value for the CTimeEx object is still in it’s uninitialised state. I’m sure that I’m probably doing something very stupid, but, having struggled with it for quite some time, I now need someone elses advice !! Thanking you in advance ! Doug

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Where do you save the time value that you send to your constructor?

        Just say 'NO' to evaluated arguments for diadic functions! Ash

        S 1 Reply Last reply
        0
        • C CPallini

          Could you please post the complete code of your class, using the 'code block' button?

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          S Offline
          S Offline
          Still learning how to code
          wrote on last edited by
          #4

          Hi, I've found the reason for my original problem, but let me explain. I was originally trying to get operator= function coded, but was floundering and trying various things. For some daft reason, at some stage, I included a private variable m_time of type time in the derived class and this (of course !) was causing the initialisation problem. However, I am still left with the problem of how to deal with operator= !! I've included my class below (hopefully in a code block - never done this before !)

          // TimeEx.h: interface for the CTimeEx class.
          //
          //////////////////////////////////////////////////////////////////////

          #if !defined(AFX_TIMEEX_H__48005666_3D56_42ED_8ADD_8F9B119E194D__INCLUDED_)
          #define AFX_TIMEEX_H__48005666_3D56_42ED_8ADD_8F9B119E194D__INCLUDED_

          #if _MSC_VER > 1000
          #pragma once
          #endif // _MSC_VER > 1000

          class CTimeEx : public CTime
          {
          public:
          CTimeEx();

          CTimeEx& CTimeEx::operator=(const CTimeEx& timeSource);
          
          CTimeEx(const CTime& TimeIn) : CTime(TimeIn) {};
          
          virtual ~CTimeEx();
          

          };

          #endif // !defined(AFX_TIMEEX_H__48005666_3D56_42ED_8ADD_8F9B119E194D__INCLUDED_)

          // TimeEx.cpp: implementation of the CTimeEx class.
          //
          //////////////////////////////////////////////////////////////////////

          #include "stdafx.h"
          #include "Test_Inhehitancy.h"
          #include "TimeEx.h"

          #ifdef _DEBUG
          #undef THIS_FILE
          static char THIS_FILE[]=__FILE__;
          #define new DEBUG_NEW
          #endif

          //////////////////////////////////////////////////////////////////////
          // Construction/Destruction
          //////////////////////////////////////////////////////////////////////

          CTimeEx::CTimeEx()
          {

          }

          CTimeEx::~CTimeEx()
          {

          }

          CTimeEx& CTimeEx::operator=(const CTimeEx& timeSource)
          {

          //  ?????????
          

          }

          Doug

          C 1 Reply Last reply
          0
          • S Still learning how to code

            Hi, I've found the reason for my original problem, but let me explain. I was originally trying to get operator= function coded, but was floundering and trying various things. For some daft reason, at some stage, I included a private variable m_time of type time in the derived class and this (of course !) was causing the initialisation problem. However, I am still left with the problem of how to deal with operator= !! I've included my class below (hopefully in a code block - never done this before !)

            // TimeEx.h: interface for the CTimeEx class.
            //
            //////////////////////////////////////////////////////////////////////

            #if !defined(AFX_TIMEEX_H__48005666_3D56_42ED_8ADD_8F9B119E194D__INCLUDED_)
            #define AFX_TIMEEX_H__48005666_3D56_42ED_8ADD_8F9B119E194D__INCLUDED_

            #if _MSC_VER > 1000
            #pragma once
            #endif // _MSC_VER > 1000

            class CTimeEx : public CTime
            {
            public:
            CTimeEx();

            CTimeEx& CTimeEx::operator=(const CTimeEx& timeSource);
            
            CTimeEx(const CTime& TimeIn) : CTime(TimeIn) {};
            
            virtual ~CTimeEx();
            

            };

            #endif // !defined(AFX_TIMEEX_H__48005666_3D56_42ED_8ADD_8F9B119E194D__INCLUDED_)

            // TimeEx.cpp: implementation of the CTimeEx class.
            //
            //////////////////////////////////////////////////////////////////////

            #include "stdafx.h"
            #include "Test_Inhehitancy.h"
            #include "TimeEx.h"

            #ifdef _DEBUG
            #undef THIS_FILE
            static char THIS_FILE[]=__FILE__;
            #define new DEBUG_NEW
            #endif

            //////////////////////////////////////////////////////////////////////
            // Construction/Destruction
            //////////////////////////////////////////////////////////////////////

            CTimeEx::CTimeEx()
            {

            }

            CTimeEx::~CTimeEx()
            {

            }

            CTimeEx& CTimeEx::operator=(const CTimeEx& timeSource)
            {

            //  ?????????
            

            }

            Doug

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #5

            Are you looking for:

            CTimeEx & CTimeEx::operator=(const CTimeEx & timeSource)
            {
            CTime::operator=(timeSource);
            return *this;
            }

            ? :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            S 1 Reply Last reply
            0
            • C CPallini

              Are you looking for:

              CTimeEx & CTimeEx::operator=(const CTimeEx & timeSource)
              {
              CTime::operator=(timeSource);
              return *this;
              }

              ? :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              S Offline
              S Offline
              Still learning how to code
              wrote on last edited by
              #6

              Thank you so much !! I now ask myself WHY I couldn't see this !! (It always seems obvious after someone has showed you, doesn't it !) Thanks again ! Doug

              C 1 Reply Last reply
              0
              • S Still learning how to code

                Thank you so much !! I now ask myself WHY I couldn't see this !! (It always seems obvious after someone has showed you, doesn't it !) Thanks again ! Doug

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                You are welcome. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                1 Reply Last reply
                0
                • L Lost User

                  Where do you save the time value that you send to your constructor?

                  Just say 'NO' to evaluated arguments for diadic functions! Ash

                  S Offline
                  S Offline
                  Still learning how to code
                  wrote on last edited by
                  #8

                  Hi Richard, As you can see from an earlier message on the thread, I had accidently tripped myself up ! I'm all sorted now - thanks anyway ! Doug

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups