This is my code to check if a class has a begin
member function or not:
template<typename T> struct has_begin { struct dummy {typedef void const_iterator;}; typedef typename std::conditional< has_iterator<T>::yes, T, dummy>::type TType; typedef typename TType::const_iterator Iter; struct fallBack{ Iter begin() const ; Iter end() const;}; struct checker : T, fallBack {}; template <typename B, B> struct cht; template<typename C> static char check(cht< Iter (fallBack::*)() const, &C::begin>*);
If I changed the second argument of cht
to check(cht< Iter (fallBack::*)() const, &C::begin>*);
to &checker::begin
, this does not change the semantics of the code, since the cht
argument of the second template is always checker
because of this enum {no = (sizeof(check<checker>(0))==sizeof(char))
but changing the code leads to error , which:
prog.cpp: In instantiation of 'has_begin<std::vector<int> >': prog.cpp:31:51: instantiated from here prog.cpp:23:38: error: reference to 'has_begin<std::vector<int> >::checker::begin' is ambiguous
I want to know what is the reason for this behavior.
Mr. Anubis
source share