Problem Initialising derived class
-
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
-
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
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] -
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
-
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]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 > 1000class 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
-
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 > 1000class 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
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] -
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]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
-
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
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] -
Where do you save the time value that you send to your constructor?
Just say 'NO' to evaluated arguments for diadic functions! Ash
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