|
I have a little problem with the assignement operator and inheritance. How does this work:
class CBaseClass{
int m_intB;
const CBaseClass& operator=(const CBaseCase& b);
}
class CDerivedClass : public CBaseClass{
int m_intD;
const CDerivedClass& operator=(const CDerivedClass& d);
}
Both assignement operators are defined like this
const CBaseClass& CBaseClass::operator=(const CBaseClass& b){
m_intB=b.m_intB;
return *this;
}
Subsequently
CDerivedClass* a_obj=new CDerivedClass;
a_obj.m_intB=5;
a_obj.m_intD=6;
CDerivedClass* b_obj=new CDerivedClass;
If I do
*b_obj=*a_obj;
only the CBaseClass member is assigned.
Is it possible to make the assignement operator virtual?
Regards, Haakon S.
A sure cure for seasickness is to sit under a tree.
Spike Milligan
|
|
|
|
|
Oops, a small error.
The statements:
a_obj.m_intB=5;
a_obj.m_intD=6;
shall of course be:
a_obj->m_intB=5;
a_obj->m_intD=6;
Haakon S.
A sure cure for seasickness is to sit under a tree.
Spike Milligan
|
|
|
|
|
Haakon S. wrote:
only the CBaseClass member is assigned
I would have thought only the CDerivedClass member would be assigned
What I would do is call the base class operator= from the derived class operator= to assign the base class members
const CDerivedClass& CDerivedClass::operator =(const CDerivedClass &d)
{
*(CBaseClass *)this = (CBaseClass &)d;
m_intD = d.m_intD;
return *this;
}
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
PJ Arends wrote:
I would have thought only the CDerivedClass member would be assigned
No, actually this assignes values for the base class:
*b_obj=*a_obj;
To assign values for the derived class I have to write:
*(CDerivedClass*)b_obj=*(CDerivedClass*)a_obj;
This is what is puzzling me. This is happening even if the type is CDerivedClass for both objects
Regards, Haakon.
A sure cure for seasickness is to sit under a tree.
Spike Milligan
|
|
|
|
|
That is truely wierd
You have to type cast a CDerivedClass pointer to a CDerivedClass pointer to call a CDerivedClass member function?!?
There is obviously something else going on that you have not posted here. Have you tried doing a "Rebuild All"?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
PJ Arends wrote:
Have you tried doing a "Rebuild All"?
Oh, yes. I have rebuilt many times, and the behaviour is definitively as described.
This is confusing, and I can't find any documentation about it. Which is frustrating.
Regards, Haakon S.
A sure cure for seasickness is to sit under a tree.
Spike Milligan
|
|
|
|
|
Sorry, got it now.
The pointers are declared as CBaseClass pointers initially, but I've tried to cast them to CDerivedClass pointers permanently. That appears to have failed. Then it makes sence:
*pBaseB=*pBaseA;
will assign values for base class, where:
*(CDerivedClass*)pBaseB=*(CDerivedClass*)pBaseA;
will assign values for the derived class.
Regards, Haakon S.
|
|
|
|
|
Your derived class's operator = must call the base class's operator =. Something like
class Derived : public Base
{
int m_intD;
public:
const Derived & operator=(const Derived &obj)
{
Base::operator =(obj);
m_intD = obj.m_intD;
return *this;
}
};
Yes, operators can be virtual but their arguments need to match perfectly. If Base's operator = takes const Base &, then Derived's operator = must also take const Base &. You'd have to do a dynamic_cast to see whether it actually is a Derived instance.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
the source code of Cadlib for creating dxf is not downloading. i need it in my project so please help me to fix this problem or tell me any method of importing a dxf file in my project.
looking forward for ur positive response
thanking u
saqib sohail
|
|
|
|
|
Hi
First of all, I am not sure if this is the right forum to ask this question but I know that this is the most-likely forum where I can get answer to this
I want to host a Managed form in an Unmanaged host(MFC's MDI window). I have been able to host a Manged Control in Unamanged MDI Window(I did this by overriding COleControlSite's CreateControl Method), but I haven't been able to do so with a Form. What I have observed is that there are some interfaces which a Managed WinForm doesnot implement and which are needed to get it hosted in the Unmanaged View. One solution which I have come up with is to implement those interfaces myself but I know this is not a good solution. Can anyone show me some pointers towards the solution of this problem.
Regards,
Aamir
Einstein: "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."
My Articles
|
|
|
|
|
Aamir Butt wrote:
One solution which I have come up with is to implement those interfaces myself but I know this is not a good solution.
That's probably the best solution.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
how to make setup in visual c++
|
|
|
|
|
|
how do i create a pop up message near the right hand corner of the task bar. by pop up message i mean that the box displaying the message should come up on its own as well as disappear on its own. also i want to implement it without using MFC. how do i do?
kindly help
|
|
|
|
|
I know I've seen articles here on that subject, search for "(taskbar OR tray) notification window" or something like that. (BTW, MS calls that style of popup "toast", like toast popping up from the toaster. )
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
maybe this will help you.
"Go as far as you can see,and when you get there you’ll see further" - Unknown
|
|
|
|
|
No. i want an non MFC based application. can u provide me with some help
|
|
|
|
|
MFC is a thin wrapper around the windows API. The article provides the how-to of the question you asked, you just have to strip out the MFC stuff to get the API stuff you want.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
Anonymous wrote:
can u provide me with some help
Sure,Why dont you try it by urself, I will love to assist you in your problem!.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Please help me.
I use the SHSetFolderPath function to Assigns a new path to a system folder through its CSIDL.But it return fail.The source code as follow:
HRESULT hr = NULL;
HINSTANCE hLib = NULL;
typedef HRESULT (WINAPI *SHSetFolderPath(int,HANDLE,DWORD,WCHAR*);
hLib = LoadLibrary("shell32.dll");
if(hLib)
{
SHSetFolderPath lpfSHSetFolderPath;
lpfSHSetFolderPath = (SHSetFolderPath)GetProcAddress(hLib,(LPTSTR)232);
hr = lpfSHSetFolderPath(CSIDL_FAVORITES,NULL,0,L"E:\\TestFolder");
}
The "hr" return value is not S_OK,why?
Thanks
|
|
|
|
|
What is the value of hr? Did you use the "Error Lookup" tool to see what that value means?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
The value of "hr" is -2147024809.I cannot find there is some problem about the parameter.
|
|
|
|
|
Hi, i'm trying to read the output of an accelerometer using the parallel port. The output of the accelerometer is a pulse width.
The question:
1. My system is Windows 2000, for some reason it won't allow me to read from the port. I have installed one of the dll suggested in the examples
2. How do I read the rise time or duty cycle of the pulse width.
3. IS Matlab implemenatation better
Thanks a lot
|
|
|
|
|
Read this article about parallel port communications.
About the rise time and the duty cycle, I am not completely sure on how to track down the time that it takes for the signal to switch from 0 to 1. You could sample the input at very high clock rates but in order to do that you need some background on timers so take a look at this other article.
// Afterall, I realized that even my comment lines have bugs
If the sun were to blow up, it would take us 7-8 minutes to realize it.
|
|
|
|
|
I ran accross a protection tool called Ultraprotect. Here's something that caught my attention: www.ultraprotect.com/dynamiccode.htm[^]. There's a prolog / epilog style encryption decryption (most likely done in __asm blocks). This makes the crackers life a tad bit harder by making them unpack certain parts of the code manually.
I'd like to learn how to implement something like this myself. If anyone has experience with this type of coding please give me some helpful links/pointers.
Alex Korchemniy
|
|
|
|