I have the following code:
#include <iostream>
template<typename T>
void gaga(T * a){
std::cout << "gaga(T * a)";
}
template<typename T> class A{};
template<typename T>
void gaga(A<T> & a){
std::cout << "gaga(A<T> & a)\n";
}
template<typename T>
class B {
public:
T * p;
operator T*() const{
std::cout << "Cast called" <<std::endl;
return p;
}
};
int main()
{
B< A<int> > b;
gaga(*b); /// WHAT IS GOING ON HERE? WHY is void gaga(A<T> & a) CALLED?
A<int> * p;
gaga(p); /// WHEN THE ABOVE calls void gaga(A<T> & a) WHY is here
/// void gaga(T * a) CALLED???
}
And I am really puzzled why the gaga(A<T> & a)
is called when I call it with *b
which obviously results by the conversion operator in A<T> *
but why?? ---> *b
is a dereference operator not even defined!?? why can that be handed even to gaga(A<T> & a)
?
Thanks for an explanation!