Thread: Can you inherit Methods into other methods?

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    141

    Can you inherit Methods into other methods?

    Like for example:
    Code:
    class  MyClass {
    
    public:
       int Method1 (void);
       int Method2 (void) : Method1 ( void ); 
    
    };
    Is this possible?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, it is not possible.
    Instead, call Method2 from within Method1.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    141
    Quote Originally Posted by Elysia View Post
    No, it is not possible.
    Instead, call Method2 from within Method1.
    Okay, does the same go for foreign classes?

    Like so:

    Code:
    class myclass {
    
     public:
      int method_to_myclass2(void);
    
    
    }
    
    class myclass2 {
    
     public:
    
      int MyMethod(void) : myclass::method_to_myclass2(void);
    
    }

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's the same. It's not possible.
    Instead, inherit from the class itself.
    You should not inherit specific methods; it's usually an indication of poor design.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    141
    Quote Originally Posted by Elysia View Post
    It's the same. It's not possible.
    Instead, inherit from the class itself.
    You should not inherit specific methods; it's usually an indication of poor design.
    But I've seen code from some big projects ( e.g. firefox ) and they do the same.

    hmm.. Anyway, do you have a website that gives me everything about classes?

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You should start dividing your concept into objects. Not methods or functions, because they are part of the objects.
    Then if something is related to another class somehow, like say a cat to animal, then the cat class can inherit from the animal class and thus get access to all of its data and functions (although only protected/public).

    For references, see cprogramming tutorials or get a good book. Plenty of suggestions in the book thread. That's all the advice I can give.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generalising methods to handle multiple weapon types
    By Swarvy in forum Game Programming
    Replies: 2
    Last Post: 05-22-2009, 02:52 AM
  2. Turn Based Stradegy System Methods
    By TylerMoyer in forum Game Programming
    Replies: 2
    Last Post: 07-30-2007, 10:45 PM
  3. Friend cannot inherit from private subclass
    By MWAAAHAAA in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2006, 04:44 PM
  4. Lesson #5 - Methods
    By oval in forum C# Programming
    Replies: 1
    Last Post: 05-04-2006, 03:09 PM
  5. Replies: 8
    Last Post: 07-27-2003, 01:52 PM