Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2007

Tip: Looking for answers? Try searching our database.

Overriding Object::ToString()

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
etam - 12 Nov 2007 01:04 GMT
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?

Here is the code:
http://eugeneciurana.com/pastebin/pastebin.php?show=5333

Thanks in advance,
Etam.
David Lowndes - 12 Nov 2007 07:45 GMT
>why I can not override it?
>
[quoted text clipped - 6 lines]
>Here is the code:
>http://eugeneciurana.com/pastebin/pastebin.php?show=5333

Etam,

The code shown there compiles fine for me with VS2005.

Dave
etam - 12 Nov 2007 10:35 GMT
> >why I can not override it?
>
[quoted text clipped - 12 lines]
>
> Dave

Is it possible that Vista is the cause?
http://odwrotnie.homeip.net/ToString.PNG

Thanks,
Etam.
David Lowndes - 12 Nov 2007 12:23 GMT
>> >Here is the code:
>> >http://eugeneciurana.com/pastebin/pastebin.php?show=5333
[quoted text clipped - 7 lines]
>Is it possible that Vista is the cause?
>http://odwrotnie.homeip.net/ToString.PNG

I wouldn't have thought so. Which version of VS are you using?

Your code in that picture isn't precisely what's shown at that
previous link, so what else is different?

Do you have a small self contained example that reproduces this?

Dave
etam - 12 Nov 2007 14:02 GMT
> I wouldn't have thought so. Which version of VS are you using?

2005...

> Your code in that picture isn't precisely what's shown at that
> previous link, so what else is different?

It is the same... I've copied and pasted it.

> Do you have a small self contained example that reproduces this?

I don't really understand what do You mean ;).

> Dave

Thanks,
Etam.
David Lowndes - 12 Nov 2007 15:12 GMT
>> Your code in that picture isn't precisely what's shown at that
>> previous link, so what else is different?
>
>It is the same... I've copied and pasted it.

It's not, the name has changed at the very least.

>> Do you have a small self contained example that reproduces this?
>
>I don't really understand what do You mean ;).

An entire single file that compiles - just stick everything in the
main source file of a console project that reproduces the issue for
you (since what you showed is fine for me).

Dave
etam - 12 Nov 2007 16:51 GMT
> It's not, the name has changed at the very least.

You are right, sorry :).
Ben Voigt [C++ MVP] - 12 Nov 2007 16:39 GMT
> Is it possible that Vista is the cause?
> http://odwrotnie.homeip.net/ToString.PNG

No, but you are missing "using namespace System;" so the name "String" is
confusing the compiler.

> Thanks,
> Etam.
etam - 12 Nov 2007 16:52 GMT
> > Is it possible that Vista is the cause?
> >http://odwrotnie.homeip.net/ToString.PNG
>
> No, but you are missing "using namespace System;" so the name "String" is
> confusing the compiler.

Thanks! You are right...
Peter Anthony - 16 Nov 2007 21:52 GMT
Why does String::ToString even exist? Why is there a method that converts a
String to a String? Isn't that a no-op? ;) I can see why you'd want to
override it, it should do nothing as it is...

And how does one find out what built-in methods are virtual/overridable? I
had no idea I could redefine ToString( ) for example. By experimentation
only, or is there a reference for this? MSDN2 isn't much help, you have to
know the answer before you can look up the question!!! lol

>> > Is it possible that Vista is the cause?
>> >http://odwrotnie.homeip.net/ToString.PNG
[quoted text clipped - 3 lines]
>
> Thanks! You are right...
Ben Voigt [C++ MVP] - 29 Nov 2007 15:05 GMT
> Why does String::ToString even exist? Why is there a method that converts
> a

So that you can call ToString on *any* object.

> String to a String? Isn't that a no-op? ;) I can see why you'd want to

Yes, it is a no-op.

> override it, it should do nothing as it is...
>
> And how does one find out what built-in methods are virtual/overridable? I
> had no idea I could redefine ToString( ) for example. By experimentation
> only, or is there a reference for this? MSDN2 isn't much help, you have to
> know the answer before you can look up the question!!! lol

You're right about that, even the class member list on msdn doesn't indicate
virtual-ness.

I think Reflector indicates virtual members with a different icon though
(there seems to be a correlation between the double pink box and
virtual/override functions).

>>> > Is it possible that Vista is the cause?
>>> >http://odwrotnie.homeip.net/ToString.PNG
[quoted text clipped - 4 lines]
>>
>> Thanks! You are right...
Peter Anthony - 16 Nov 2007 21:54 GMT
PS - etam,  don't you think your name is a little bit 'backwards, mate'?
hehe

>> > Is it possible that Vista is the cause?
>> >http://odwrotnie.homeip.net/ToString.PNG
[quoted text clipped - 3 lines]
>
> Thanks! You are right...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.