Hello,
I am developing a cross platform library and I am running into a compile error which I only get in Windows and not Linux. I have declared the operator<<() as a friend inside of a class which has a nested struct within it. However, the compiler is throwing an error stating that the object is private to the class(which is true), disregarding what seems to me to be the required allowance to grant access to the nested struct.
This is the basics of the code. Hopefully you can see what is causing the error, as I am not able to. I have reasons to nest the struct within the class which I would prefer not to work around.
In the header file:
namespace sa {
class Format {
struct Bound_form {
const Format& format;
std::string string;
};
friend std::ostream& operator<< (
std::ostream&, const Format::Bound_form&);
// other private members
public:
// public members
};
std::ostream& operator<< (
std::ostream& out, const Format::Bound_form& formed_string);
}
In the .cpp source file:
//This is where the error throws
std::ostream& sa::operator<< (
std::ostream& out, const sa::Format::Bound_form& formed_string)
{
// print out the formed string using the Bound_form's Format
}
I know that this setup can be used to expose private members (I have done this myself) as well as private classes (as described here in Microsoft documentation). I'm just not quite sure what I'm missing here.
Any help will be much appreciated.