//MyClass.h
#ifndef HEADER
#define HEADER
//Everything in header should be inside guards
#include <iosfwd> //Try to not bring iostream to those not wanting it
class MyClass
{
//stuff
};
std::ostream& operator<<(std::ostream&, const MyClass&); //Declaration only
#endif
//Myclass.cpp
#include "MyClass.h"
#include <iostream>
/* Class member definition */
//Operator definition
std::ostream& operator<<(std::ostream& out, const MyClass& c)
{
//...
return out;
}
//main.cpp
#include <iostream>
#include "MyClass.h"
int main()
{
MyClass foo;
std::cout << foo;
}