Thread: object methods

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    86

    object methods

    Is it possible to write a method which accepts dot notation from system objects?

    for example, is it possible to write soething liek this:

    Code:
    string str;
    
    str.method(args){ statements; }
    where method is not defined is string.h?

  2. #2
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152
    I donīt think so. Why would you need such thing?

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    No, you cannot. What is included in a class is fixed. What you might be able to do, however, is create a derived class that adds the new method that you want added.
    Code:
    class MyDerivedString : public string
    {
    public:
       void method();
    };
    
    void MyDerivedString::method()
    {
       cout << "method() has been called" << std::endl;
    }
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Object destroy itself?
    By cminusminus in forum C++ Programming
    Replies: 28
    Last Post: 03-27-2008, 01:08 AM
  2. using this as synchronization object
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 03-22-2008, 07:49 AM
  3. Question about cout an stack object?
    By joenching in forum C++ Programming
    Replies: 8
    Last Post: 05-08-2005, 10:10 PM
  4. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  5. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 13
    Last Post: 10-31-2002, 02:56 PM