Overriding Object::ToString()

Overriding Object::ToString()

am 07.11.2007 15:36:50 von etam

Hi,

why I can not override it?

This line: virtual String^ ToString() override = Object::ToString;
produces this error: cannot override base class method
'System::Object::ToString'.

Why is that?

Tnaks in advance,
Etam.

Re: Overriding Object::ToString()

am 08.11.2007 08:45:12 von skeet

Etam wrote:
> why I can not override it?
>
> This line: virtual String^ ToString() override = Object::ToString;
> produces this error: cannot override base class method
> 'System::Object::ToString'.
>
> Why is that?

I'm not familiar with the C++ syntax, but perhaps if you showed a
complete demonstration it would be easier to see what's wrong?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet -
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Re: Overriding Object::ToString()

am 08.11.2007 17:06:26 von etam

There is the code:

http://eugeneciurana.com/pastebin/pastebin.php?show=5225

Re: Overriding Object::ToString()

am 09.11.2007 12:55:57 von skeet

Etam wrote:
> There is the code:
>
> http://eugeneciurana.com/pastebin/pastebin.php?show=5225

Hmm. Looking at a couple of online examples, my guess is that you don't
need to respecify "virtual". On the other hand, that wouldn't really
fit with the compiler message...

Sorry not to be able to help you further :(

--
Jon Skeet -
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Re: Overriding Object::ToString()

am 09.11.2007 20:08:57 von etam

On 9 Lis, 12:55, Jon Skeet [C# MVP] wrote:
> Etam wrote:
> > There is the code:
>
> >http://eugeneciurana.com/pastebin/pastebin.php?show=5225
>
> Hmm. Looking at a couple of online examples, my guess is that you don't
> need to respecify "virtual". On the other hand, that wouldn't really
> fit with the compiler message...
>
> Sorry not to be able to help you further :(
>
> --
> Jon Skeet - http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too

When I remove virtual i get the error:
'override' requires 'virtual' :(

The strange thing is that this:
http://pastebin.com/m4661ce7b
WORKS :/.

Re: Overriding Object::ToString()

am 10.11.2007 21:22:48 von skeet

Etam wrote:
> On 9 Lis, 12:55, Jon Skeet [C# MVP] wrote:
> > Etam wrote:
> > > There is the code:
> >
> > >http://eugeneciurana.com/pastebin/pastebin.php?show=5225
> >
> > Hmm. Looking at a couple of online examples, my guess is that you don't
> > need to respecify "virtual". On the other hand, that wouldn't really
> > fit with the compiler message...
> >
> > Sorry not to be able to help you further :(
>
> When I remove virtual i get the error:
> 'override' requires 'virtual' :(
>
> The strange thing is that this:
> http://pastebin.com/m4661ce7b
> WORKS :/.

Hmm.

Can you just put the override in the CPP file without declaring it in
the .h file perhaps?

I'd suggest asking in the specific C++ group though - you're bound to
get an answer there.

--
Jon Skeet -
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too