An ambiguous call if the class inherits from 2 template parent classes. What for?

I have a template class that takes an action on the class specified as an argument to the template. For some of my classes, I want to β€œgroup” the functionality in one class to facilitate calling the caller. Actually, the code looks something like this (names 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 ProcessFrontEnd :: process with the CustomerOrder argument as an argument, 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, the Microsoft 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

(char + void *, double + void *) ('c', 3.14), .

VS2005 VS2010, .

? ? Microsoft?

EDIT: 2 push_back , :

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

. , void. , push_back ?

+3
3

. . (. 10.2.2). , , (.. ). , . , .

, C A B . B A:: foo() B:: foo(), .

, , , - .

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

X.

+3

, ++, . , , process(CustomerOrder) process(ProductionOrder).

- using , .

+2

How should the compiler know which process you want to name? There are two options. Do you want both, one or the other?

You need to redefine the process in the derived class.

-1
source

Source: https://habr.com/ru/post/1761296/


All Articles