Including typedef of child in parent class

Posted by Baz on Stack Overflow See other posts from Stack Overflow or by Baz
Published on 2012-09-13T15:36:16Z Indexed on 2012/09/13 15:38 UTC
Read the original article Hit count: 136

Filed under:

I have a class which looks something like this. I'd prefer to have the typedef of ParentMember in the Parent class and rename it Member. How might this be possible? The only way I can see is to have std::vector as a public member instead of using inheritance.

typedef std::pair<std::string, boost::any> ParentMember;
class Parent: public std::vector<ParentMember>
{
public:
    template <typename T>
    std::vector<T>& getMember(std::string& s)
    {
        MemberFinder finder(s);
        std::vector<ParentMember>::iterator member = std::find_if(begin(), end(), finder);
        boost::any& container = member->second;
        return boost::any_cast<std::vector<T>&>(container);
    }
private:
    class Finder
    {
      ...
    };
};

© Stack Overflow or respective owner

Related posts about c++