V
valoh
Hi,
is this legal c++ code?
template <typename BaseT> struct A
{
BaseT& this_() { return *static_cast<BaseT*>(this); }
template <typename T> void Foo() { this_().Bar<T>(); }
template <typename T> void Bar() { }
template <typename T> void Bar(i32) { }
};
struct B : public A<B>
{
using A<B>::Bar;
template <typename T> void Bar() { }
};
//..
B test; test.Foo<int>();
when using such a construction I got mixed results on various
compiler. Often I get an ambiguous call to overloaded function error
(A<B>::Bar() vs B::Bar()). Sometime it seem to make a difference when
using template member function or non-template member function.
If it is not legal, why not? Any ideas for good workarounds? I have
template member functions for which i want default implementations and
helpers/wrappers in the base class. Several directly from this base
class derived classes only implementing a subset of the default
implementation. Any ideas?
is this legal c++ code?
template <typename BaseT> struct A
{
BaseT& this_() { return *static_cast<BaseT*>(this); }
template <typename T> void Foo() { this_().Bar<T>(); }
template <typename T> void Bar() { }
template <typename T> void Bar(i32) { }
};
struct B : public A<B>
{
using A<B>::Bar;
template <typename T> void Bar() { }
};
//..
B test; test.Foo<int>();
when using such a construction I got mixed results on various
compiler. Often I get an ambiguous call to overloaded function error
(A<B>::Bar() vs B::Bar()). Sometime it seem to make a difference when
using template member function or non-template member function.
If it is not legal, why not? Any ideas for good workarounds? I have
template member functions for which i want default implementations and
helpers/wrappers in the base class. Several directly from this base
class derived classes only implementing a subset of the default
implementation. Any ideas?