C++ multiple inheritance - diamond with templates -
i've got problem when inheriting multiple instances of template.
my class bridge tries inherit 2 instances of bridgetemplate, when try call bridgetemplate's 'set' function, compiler rises error ("ambiguous..."). however, works ok if bridge inherits 1 instance.
below, piece of code both template , class bridge. in advance
template <class datatype, class datawriter> class bridgetemplate : public bridgegeneric { public: void set(datatype a, datawriter b) { std::cout << "a: " << << "; b: " << b << std::endl; } ... }; class bridge : public virtual bridgetemplate<int,float>, public virtual bridgetemplate<float,int> { ... }
argument types not matter.
the error message applies name lookup, not overload resolution. overloaded functions must come same class or namespace. in order insure that, use pattern:
class child : public dad, public mom { using dad::func; using mom::func; }; // ... child c; c.foo(1, 2.3);
because of using
declarations, both func
members brought child
namespace , lookup no longer ambiguous.
Comments
Post a Comment