I've got a problem when inheriting from multiple instances of a template.
My class Bridge tries to inherit from 2 instances of BridgeTemplate, so when we try to call the BridgeTemplate's 'set' function, the compiler rises an error ("ambiguous..."). However, everything works ok if Bridge inherits from only 1 instance.
Below, a piece of code from both the template and class Bridge. Thanks in advance
template <class DataType, class DataWriter>
class BridgeTemplate : public BridgeGeneric
{
public:
void set(DataType a, DataWriter b)
{
std::cout << "a: " << a << "; b: " << b << std::endl;
}
...
};
class Bridge : public virtual BridgeTemplate<int,float>, public virtual BridgeTemplate<float,int>
{
...
}
Argument types do not matter.
The error message applies to name lookup, not to overload resolution. All overloaded functions must come from the same class or namespace. In order to insure that, use this pattern:
class Child : public Dad, public Mom {
using Dad::func;
using Mom::func;
};
// ...
Child c;
c.foo(1, 2.3);
Because of the using
declarations, both func
members are brought to the Child
namespace and the lookup is no longer ambiguous.
I've got a problem when inheriting from multiple instances of a template.
My class Bridge tries to inherit from 2 instances of BridgeTemplate, so when we try to call the BridgeTemplate's 'set' function, the compiler rises an error ("ambiguous..."). However, everything works ok if Bridge inherits from only 1 instance.
Below, a piece of code from both the template and class Bridge. Thanks in advance
template <class DataType, class DataWriter>
class BridgeTemplate : public BridgeGeneric
{
public:
void set(DataType a, DataWriter b)
{
std::cout << "a: " << a << "; b: " << b << std::endl;
}
...
};
class Bridge : public virtual BridgeTemplate<int,float>, public virtual BridgeTemplate<float,int>
{
...
}
Argument types do not matter.
The error message applies to name lookup, not to overload resolution. All overloaded functions must come from the same class or namespace. In order to insure that, use this pattern:
class Child : public Dad, public Mom {
using Dad::func;
using Mom::func;
};
// ...
Child c;
c.foo(1, 2.3);
Because of the using
declarations, both func
members are brought to the Child
namespace and the lookup is no longer ambiguous.
0 commentaires:
Enregistrer un commentaire