D
Daniel
I was trying to use a set of mixins which declare the functions with
the same names, but take different argument types. However, gcc
complains that the function calls are ambiguous unless I use a "using"
to explicitly bring the calls in to the scope of the outer class. I
presume the cause is something like that the search won't search all
base classes before trying to resolve the call, but I'm not really
clear. Is there an easier workaround than putting a "using" statement
for each base class/function combination? Thanks. Example code below.
#include <iostream>
template <class T>
class Mixin {
public:
void take(T t) {
std::cout << t << std::endl;
}
};
class Master0: public Mixin<int>,
public Mixin<float> {
public:
};
class Master1: public Mixin<int>,
public Mixin<float> {
public:
using Mixin<int>::take;
using Mixin<float>::take;
};
class Master2 {
public:
void take(int t) {
std::cout << t << std::endl;
}
void take(float t) {
std::cout << t << std::endl;
}
};
void driver() {
Master0 m0;
// fails with error about an ambiguous call
m0.take(1);
Master1 m1;
m1.take(1);
Master2 m2;
m2.take(1);
}
the same names, but take different argument types. However, gcc
complains that the function calls are ambiguous unless I use a "using"
to explicitly bring the calls in to the scope of the outer class. I
presume the cause is something like that the search won't search all
base classes before trying to resolve the call, but I'm not really
clear. Is there an easier workaround than putting a "using" statement
for each base class/function combination? Thanks. Example code below.
#include <iostream>
template <class T>
class Mixin {
public:
void take(T t) {
std::cout << t << std::endl;
}
};
class Master0: public Mixin<int>,
public Mixin<float> {
public:
};
class Master1: public Mixin<int>,
public Mixin<float> {
public:
using Mixin<int>::take;
using Mixin<float>::take;
};
class Master2 {
public:
void take(int t) {
std::cout << t << std::endl;
}
void take(float t) {
std::cout << t << std::endl;
}
};
void driver() {
Master0 m0;
// fails with error about an ambiguous call
m0.take(1);
Master1 m1;
m1.take(1);
Master2 m2;
m2.take(1);
}