I have a class that uses a struct, and I want to overload the << operator for that struct, but only within the class:
typedef struct my_struct_t {
in
If by "only overloaded in the My_Class" you mean only visible / usable by my class you could use a non-member overload that's only visible to My_Class. E.g.
struct my_struct {
int a;
char c;
};
class My_Class
{
publiC:
My_Class();
}
Then in My_Class.cpp:
namespace {
ostream& operator(ostream& os, const my_struct& mystruct ) {
os << mystruct.a << mystruct.c;
}
}