C
chrisstankevitz
Why does this code only compile if GLOBAL_IN_STRUCT is defined?
It creates a templated class C<T> and defines a global operator* that
takes a C<T> on the LHS and a T on the RHS.
In the example, T is double, but I call the global operator* with a
float.
Thanks for your help,
Chris
//-------------------------------------
//-------------------------------------
#define GLOBAL_IN_STRUCT
template <typename T>
struct C {
#ifdef GLOBAL_IN_STRUCT
friend void operator*(const C<T>& p, T d) {}
};
#else
};
template <typename T> void operator*(const C<T>& p, T d) {}
#endif
int main()
{
C<double> v;
v * 0.0f;
return 0;
}
It creates a templated class C<T> and defines a global operator* that
takes a C<T> on the LHS and a T on the RHS.
In the example, T is double, but I call the global operator* with a
float.
Thanks for your help,
Chris
//-------------------------------------
//-------------------------------------
#define GLOBAL_IN_STRUCT
template <typename T>
struct C {
#ifdef GLOBAL_IN_STRUCT
friend void operator*(const C<T>& p, T d) {}
};
#else
};
template <typename T> void operator*(const C<T>& p, T d) {}
#endif
int main()
{
C<double> v;
v * 0.0f;
return 0;
}