Разрешение шаблона в методе с параметром шаблона класса не работает при использовании множественного наследования в базоC++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Разрешение шаблона в методе с параметром шаблона класса не работает при использовании множественного наследования в базо

Сообщение Anonymous »

Рассмотрим следующий код: < /p>

template
struct Ambiguous_C {
void func(T);
};

struct Ambiguous_F {
template
void func(T);
};

struct Conflicted_F : public Ambiguous_F{
void test (){
func(1);
func(1);
func(1.1f);
func(1.1f);
}
};
struct Conflicted_C : public Ambiguous_C, Ambiguous_C{
void test (){
//func(1); /* Error */
Ambiguous_C::func(1);
//func(1.1f); /* Error */
Ambiguous_C::func(1.1f);
}
};
< /code>
Member 'func' found in multiple base classes of different types
< /code>
This was compiled using clang 20.1.2
I expected the function calls in Conflicted_C::test() to resolve the overloaded function call based on the function signature, just like the code shown in Conflicted_F::test().
Are there additional considerations taken into account with regards to templated classes that I am not aware of?
Is there a way to implement a templated base class/ method, such that the explicit base class Ambiguous_C:: in front of a call to func can be omitted?
EDIT:
I noticed this gives the same error:

void f_func(int);
void f_func(float);

struct Ambiguous_P1 {
void func(int);
};

struct Ambiguous_P2 {
void func(float);
};

struct Conflicted_P : public Ambiguous_P1, Ambiguous_P2{
void test() {
func(1); /* Error */
func(1.1f); /* Error */

f_func(1); /* Works */
f_func(1.1f); /* Works */
}
};
< /code>
But the question remains the same. Why is the resolution of this ambiguous call not possible based on function signature?


Подробнее здесь: https://stackoverflow.com/questions/795 ... orking-whe
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»