Discussion:
Virtual function [...] conflicts with base class... Override question
(too old to reply)
Tom420
2008-06-29 18:13:44 UTC
Permalink
It's not good practice to cross-post questions, but as I didn't get an
answer and I feel it's probably more appropriate here...

I'm not quite good at class inheritance and function override. I receive
a compiler error here which I don't understand.

class PACKAGE TMyControl : public TCustomControl
{
private:
protected:
virtual void __fastcall Paint(void);
virtual void __fastcall DoEnter(void); <---------
public:
__fastcall TMyControl(TComponent* Owner);
__published:
};

I get error message:
Virtual function '__fastcall TMyControl::DoEnter()' conflicts with base
class 'TWinControl'

Paint() is from TCustomControl, and works fine.
DoEnter() is from TWinControl (TCustomControl's ancestor)

I'm trying to override DoEnter() in order to display a carret when my
component receives focus.
Bob Gonder
2008-06-29 19:54:16 UTC
Permalink
Post by Tom420
class PACKAGE TMyControl : public TCustomControl
{
virtual void __fastcall Paint(void);
virtual void __fastcall DoEnter(void); <---------
__fastcall TMyControl(TComponent* Owner);
};
Virtual function '__fastcall TMyControl::DoEnter()' conflicts with base
class 'TWinControl'
Paint() is from TCustomControl, and works fine.
TCustomControl::Paint is virtual.
Post by Tom420
DoEnter() is from TWinControl (TCustomControl's ancestor)
TWinControl::DoEnter is DYNAMIC.
Post by Tom420
I'm trying to override DoEnter() in order to display a carret when my
component receives focus.
In your constructor, set DoEnter to your function.
__fastcall TMyControl(TComponent* Owner)
{ DoEnter = &MyDoEnter; }
Or something like that.
Tom420
2008-06-29 20:23:58 UTC
Permalink
Post by Bob Gonder
Post by Tom420
class PACKAGE TMyControl : public TCustomControl
{
virtual void __fastcall Paint(void);
virtual void __fastcall DoEnter(void); <---------
__fastcall TMyControl(TComponent* Owner);
};
Virtual function '__fastcall TMyControl::DoEnter()' conflicts with base
class 'TWinControl'
Paint() is from TCustomControl, and works fine.
TCustomControl::Paint is virtual.
Post by Tom420
DoEnter() is from TWinControl (TCustomControl's ancestor)
TWinControl::DoEnter is DYNAMIC.
Post by Tom420
I'm trying to override DoEnter() in order to display a carret when my
component receives focus.
In your constructor, set DoEnter to your function.
__fastcall TMyControl(TComponent* Owner)
{ DoEnter = &MyDoEnter; }
Or something like that.
class PACKAGE TMyControl : public TCustomControl
{
private:
protected:
virtual void __fastcall Paint(void);
virtual void __fastcall MyDoEnter(void);
public:
__fastcall TMyControl(TComponent* Owner);
__published:
};


__fastcall TMyControl::TMyControl(TComponent* Owner)
: TCustomControl(Owner)
{
DoEnter = &MyDoEnter;
}


"Member function must be called or its address taken"



The help files documents DoEnter as follow:
virtual void DoEnter ();

and the following (from the same page) makes me believe I am allowed to
override it:
"Descendant classes that override DoEnter should always call the
inherited method."


Thanks for trying, any other idea? :)
(I like challenges, I just prefer when I can find a solution lol)
Bob Gonder
2008-06-29 20:47:18 UTC
Permalink
Post by Tom420
"Member function must be called or its address taken"
If you google that phrase, you will get many hits.

MyDoEnter should not be virtual.
It should probably be static.
static void __fastcall MyDoEnter(void);
Post by Tom420
virtual void DoEnter ();
I was looking in the BCB5 help version.
Tom420
2008-06-29 22:29:22 UTC
Permalink
Post by Bob Gonder
Post by Tom420
"Member function must be called or its address taken"
If you google that phrase, you will get many hits.
MyDoEnter should not be virtual.
It should probably be static.
static void __fastcall MyDoEnter(void);
Post by Tom420
virtual void DoEnter ();
I was looking in the BCB5 help version.
Whatever just won't work. DoEnter *is* virtual, all error messages I get
tell me so. Looks like I've wasted the last 24 hrs mainly around this one.

Thanks for you help anyway Bob :)

Anyone one has any clue as to what's wrong here???
I'm using BCB 2006
Bob Gonder
2008-06-29 23:14:08 UTC
Permalink
Post by Tom420
Whatever just won't work.
Hmm, yes, I was thinking of the property OnEnter.
Post by Tom420
DoEnter *is* virtual, all error messages I get
tell me so.
Actually, no, its not. It is "virtual-like".
Post by Tom420
I'm using BCB 2006
Look at the hpp files COMCTRLS.HPP and CONTROLS.HPP
in BDS\4.0\include\vcl.

virtual void __fastcall Paint(void);
DYNAMIC void __fastcall DoEnter(void);

Search the help for dynamic:
Dynamic Functions:
{snip}
Dynamic functions cannot be made virtual, and vice-versa
You cannot redeclare a virtual function to be dynamic; likewise, you cannot redeclare a
dynamic function to be virtual. The following example gives errors:
Tom420
2008-06-29 23:45:53 UTC
Permalink
WWWOOOOORRRRKKKKSSSSSS!!!!!!!
Post by Bob Gonder
Hmm, yes, I was thinking of the property OnEnter.
Nah, I always thought it wasn't a good idea to overide a property which
is designed to be published. Not sure if it really makes a difference
though.
Post by Bob Gonder
Post by Tom420
DoEnter *is* virtual, all error messages I get
tell me so.
Actually, no, its not. It is "virtual-like".
Post by Tom420
I'm using BCB 2006
Look at the hpp files COMCTRLS.HPP and CONTROLS.HPP
in BDS\4.0\include\vcl.
That is the step I didn't do, go check the hpp files. The help files
says 'virtual' and I stuck to it. Now I know what to trust the best.
Trust me, I learn from my mistakes.
Post by Bob Gonder
virtual void __fastcall Paint(void);
DYNAMIC void __fastcall DoEnter(void);
{snip}
Dynamic functions cannot be made virtual, and vice-versa
You cannot redeclare a virtual function to be dynamic; likewise, you cannot redeclare a
Yes indeed I checked. Makes sense that the compiler still use 'virtual'
as it's pretty close, but it might be easier to debug if it said 'dynamic'

Now I can go on with my project, thanks to you! This is were men stands
apart from the children (and yes, I feel just like a kid now lol)

Thanks again to you. Got some time before we both got there, but without
your help I would still be playing the Sims lol

Now it's July 1st in just 2 days. That means 'moving out day' for us
here in Quebec. Gotta have that project on standby for a couple of days.
Remy Lebeau (TeamB)
2008-06-30 04:56:33 UTC
Permalink
Post by Tom420
DoEnter *is* virtual
No, actually it is not. It is dynamic, not virtual. There are subtle
differences between them. See my other reply for the proper declaration.


Gambit
Remy Lebeau (TeamB)
2008-06-30 04:55:25 UTC
Permalink
Post by Bob Gonder
If you google that phrase, you will get many hits.
I guess you did not do the search yourself. The solution has been posted
many times before.
Post by Bob Gonder
MyDoEnter should not be virtual.
It should probably be static.
That is also the completely wrong thing to do. Please do some research
before posting wrong answers over and over.


Gambit
Bob Gonder
2008-06-30 16:31:06 UTC
Permalink
Post by Remy Lebeau (TeamB)
That is also the completely wrong thing to do.
Yes, I was reacting to the "obvious question" instead of digging deeper.
Post by Remy Lebeau (TeamB)
Please do some research before posting wrong answers over and over.
Well, I did eventualy get it right.
Even had the proper clue in the first rely,
but didn't recognize the significance of DYNAMIC.
C++ is hard enough to understand without extensions.

I kept expecting you to jump in and save me from myself.
But I guess you had the day off.

Remy Lebeau (TeamB)
2008-06-30 04:54:02 UTC
Permalink
Post by Bob Gonder
In your constructor, set DoEnter to your function.
__fastcall TMyControl(TComponent* Owner)
{ DoEnter = &MyDoEnter; }
Or something like that.
That is the completely wrong thing to do, not o mention is not legal code
anyway. Where did you come up with that?


Gambit
Remy Lebeau (TeamB)
2008-06-30 04:52:58 UTC
Permalink
Post by Tom420
virtual void __fastcall DoEnter(void); <---------
DoEnter() needs to be declared as DYNAMIC, not virtual:

DYNAMIC void __fastcall DoEnter(void);

DYNAMIC and 'virtual' are functionally similar, but not quite the same
thing.
Post by Tom420
Virtual function '__fastcall TMyControl::DoEnter()' conflicts with base
class 'TWinControl'
That means your overridden method is not declared exactly the same as it is
in a base class. Which is actually the case, since you used 'virtual'
instead of DYNAMIC.
Post by Tom420
Paint() is from TCustomControl, and works fine.
Paint() is declared as virtual. Your declaration for Paint() matches
correctly.


Gambit
Loading...