CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    63

    inherited classes w/ different functions under the same name

    Hello all,

    I have two different classes that are both inherited from the same parent class.
    class BaseClass {...};
    class childClass_1: public BaseClass {...};
    class childClass_2: public Baseclass {...};

    I have a vector that stores pointers to objects of the type BaseClass:
    std::vector <BaseClass *> baseObjects;

    now i want to be able to do something like this:
    int i;
    for (i=0;i<baseObjects.length();i++) {

    baseObjects.at(i)->doSomething ();

    }

    however, the contents of the function doSomething is different for childClass_1 and childClass_2. how can i arrange this? some sort of function template in BaseClass?

    Thanks in advance! I really appreciate it -
    - iochi

  2. #2
    Join Date
    Jun 2009
    Posts
    63

    Re: inherited classes w/ different functions under the same name

    I got it - virtual members.
    http://www.cplusplus.com/doc/tutorial/polymorphism/
    good luck to anyone reading this -

  3. #3
    Join Date
    Apr 2008
    Posts
    725

    Re: inherited classes w/ different functions under the same name

    yep, that's the one

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured