implicit or default method/property of a class

Posted on 2004-11-15
Last Modified: 2010-04-24
Hi all,

Is there a way to create an implicit or default method or property of a class in Managed C++?

In other words, how do I declare a ToString method so that the two statements below both call the ToString method?
  MessageBox::Show(this->myClass->ToString(), S"explicit call to ToString()");
  MessageBox::Show(this->myClass, S"implicit call to ToString()");


Question by:javanic
    LVL 19

    Expert Comment

    I cannot think of a way to do this.  The Show method wants a String* parameter so a conversion needs to be done.  Unfortunately, user-defined operators are not invoked on pointer types in C++.  This means that you'd have explicitly call the conversion operator which is no better than having to explicitly call ToString().

    You can read about managed C++ operators at
    LVL 1

    Author Comment

    Hmmm. I was hoping there was something in Managed C++ that allowed something like VB.NET default property. See I believe C# also allows that functionality. Consider the Item property--which is the default property/method of a collections class. See:

    By the way, I just found the reference to the C# functionality, though I knew it existed. I was hoping it existed in MC++ and that someone would have a reference to it... :)

    LVL 1

    Author Comment

    In case anyone is following this thread, I think I have found what I was looking for. Here is the reference to a default property declaration for Managed C++:

    LVL 19

    Accepted Solution

    You can try it, but I don't believe a default property will give you the functionality you are looking for.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video discusses moving either the default database or any database to a new volume.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now