ThisClass () statement causes a stack overflow
I want the class to be simple and not define a constructor, so I can make the data Pt = {0, 5}; so I figured the best way to convert Pt_t from short to long or vice versa is to do something like this.
template <class T>
struct Pt_t
{
T x, y;
template <class T2> operator Pt_t<T2>() { Pt_t pt = {x, y}; return pt; }
};
The compiler dislikes this and calls the Pt_t operator when it returns pt; thus getting a stack overflow. How can I prevent this? the only solution I can think of is that Pt_t uses constructors that remove Pt_t pt = {1, 2}; which I prefer to keep if I can.
I'm sure there is an unqualified Pt_t in your function body Pt_t<T>
, but don't you want it to be Pt_t<T2>
? You will need to explicitly qualify it.
I'm not familiar with C ++, but are you declaring the correct type in your method?
Shouldn't it be Pt_t<T2>
instead Pt_t
?