I have a class within a namespace like following. test.h
#include <iostream>
using std::cout;
namespace n1
{
class myClass;
}
class n1::myClass
{
public:
myClass(int na, int nb):a(na), b(nb){}
private:
int a;
int b;
friend std::ostream& operator << (std::ostream & stream, const n1::myClass& cls);
};
test.cpp
#include "test.h"
std::ostream& operator << (std::ostream & str, const n1::myClass& cls)
{
str << cls.a << " " << cls.b << std::endl;
}
On Compilation, I am getting following error.
test.h: In function ‘std::ostream& operator<<(std::ostream&, const n1::myClass&)’:
test.h:13:6: error: ‘int n1::myClass::a’ is private
test.cpp:5:13: error: within this context
test.h:14:6: error: ‘int n1::myClass::b’ is private
test.cpp:5:29: error: within this context
How do I get past the errors?