Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1029091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:29:21+00:00 2026-05-16T12:29:21+00:00

I have a templated class that performs an action on the class that is

  • 0

I have a templated class that performs an action on the class that is given as template argument. For some of my classes I want to ‘group’ the functionality in one class, to make it easier for the caller. In fact the code looks something like this (names were changed):

template<typename T>
class DoSomeProcessing
{
public:
   process(T &t);
};

class ProcessingFrontEnd : public DoSomeProcessing<CustomerOrder>, public DoSomeProcessing<ProductionOrder>
{
};

The problem is that when I call ProcessingFrontEnd::process with a CustomerOrder as argument, that the compiler complains about it.

I tried to reproduce the problem in a smaller test application. This is the code:

#include <vector>

class X : public std::vector<char>
        , public std::vector<void *>
{
};

int main(void)
{
X x;
x.push_back('c');
return 0;
}

And indeed, if this is compiled, Microsoft’s VS2010 compiler gives this error:

test.cpp
test.cpp(11) : error C2385: ambiguous access of 'push_back'
        could be the 'push_back' in base 'std::vector<char,std::allocator<char> >'
        or could be the 'push_back' in base 'std::vector<void *,std::allocator<void *> >'
test.cpp(11) : error C3861: 'push_back': identifier not found

I tested this test application with different types (char+void*, double+void*) and different arguments in the call (‘c’, 3.14), but the error message is always the same.

I tested this with VS2005 and VS2010 but I always get the same error.

Why can’t the compiler determine the correct function to call? What makes this confusing for the compiler? Or is it just a bug in the Microsoft compiler?

EDIT:
If I explicitly add 2 push_back methods to my class, like this:

class X : public std::vector<char>
        , public std::vector<void *>
{
public:
   void push_back(char c) {}
   void push_back(void *p) {}
};

The compiler doesn’t complain anymore. So with these methods he can clearly distinguish between a character and a void-pointer. Why can’t he do this if the two push_back methods are inherited from the parent?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:29:21+00:00Added an answer on May 16, 2026 at 12:29 pm

    This is by design. The compiler is not trying to resolve overloaded
    functions because these are not overloaded
    functions. The standard is really clear on that
    (see 10.2.2). If the same name is found in two
    different bases, it’s an ambiguity, even if they
    could be resolved correctly with the call (i.e. in
    your case). Same-named functions in different classes will typically have quite different purposes and hence the selection between them should not be made on the basis of
    their arguments. There are many good reasons not to
    allow that, but here’s one.

    Imagine your class C derives from A and B and
    these two base classes come from two different
    libraries. If the author of B adds a new function
    to the class, it may break the user’s code by
    redirecting a call from A::foo() to B::foo() if
    the latter is a better match.

    If you want the two functions to be treated in the same way that they would
    be if part of a single class, then the best way to do it is with using
    declarations in the derived class. Just add

    using std::vector<char>::push_back;
    using std::vector<void *>::push_back;
    

    to the declaration of class X.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.