I have a class that uses struct, and I want to overload the <operator for this structure, but only inside the class:
typedef struct my_struct_t {
int a;
char c;
} my_struct;
class My_Class
{
public:
My_Class();
friend ostream& operator<< (ostream& os, my_struct m);
}
I can only compile when I declare the operator <<overload with the keyword friend, but then the operator is overloaded everywhere in my code, and not just in the class. How to overload the <<statement for my_struct ONLY inside the class?
Edit: I want to use the overloaded print statement my_struct, which is a member of My_Class
source
share