I am hoping to get some help with an error I am getting - I have searched similar questions which havent really gave me what I'm after. A code snippet is listed below:
class NewSelectionDlg : public CDialog
{
// Construction
public:
class CProductListBox
{
public:
friend ostream& operator <<(ostream& o, const CProductListBox& b);
};
ostream& operator<<(ostream& o, const CProductListBox& b)
{
std::cout << o.m_lstEclispeProducts;
return o;
}
I have a list box that contains a number of strings - these can vary depending on other drop down boxes selected. I want to what is in this box to a file as well as what the user selects from the drop downs that popluate it. Howvever I am getting the following error (I am developing in VS 2008).
error C2804: binary
'operator <<'
has too many parameters
error C2333:'NewSelectionDlg::operator <<'
: error in function declaration; skipping function body
I am not sure why as i belive the syntax of overloading the operator is OK - can anyone see anything I have done stupid or may have missed - Many Thanks for any Help.
Just define it outside of class definition or define it in subclass when declaring friendship:
class NewSelectionDlg : public CDialog
{
// Construction
public:
class CProductListBox
{
public:
friend ostream& operator <<(ostream& o, const CProductListBox& b);
};
// (...) Rest of NewSelectionDlg
};
ostream& operator <<(ostream& o, const NewSelectionDlg::CProductListBox& b)
{
// Did you meant:
return o << b.m_lstEclispeProducts;
}
or
class NewSelectionDlg : public CDialog
{
// Construction
public:
class CProductListBox
{
public:
friend ostream& operator <<(ostream& o, const CProductListBox& b)
{
// Did you meant:
return o << b.m_lstEclispeProducts;
}
};
// (...) Rest of NewSelectionDlg
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With