Using private class members in a friend function

Hi, all.

I'm trying to overload the << operator as a friend function in a class definition I'm writing. I've been told that in order to use any of the private members of the class in the function in this case, I have to give the scope of the class. My issue is, Visual Studio keeps telling me these private data members are inaccessible in the friend function.
Here's the code. First, from the header:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class TextItem
{
friend ostream& operator<<
        (
        ostream& outStream,  //inout
        const TextItem& item //in
        );

private:
    struct LineNode
    {
        string lineText;
        LineNode* next;
    };
    LineNode* firstLinePtr;
};


And here's the definition of the operator<< function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 ostream& operator<<
        (
        ostream& outStream,  //inout
        const TextItem& item //in
        )
    {

        TextItem::LineNode* currentLinePtr = item.firstLinePtr; // <-- says both values are inaccessible.
        while(currentLinePtr != nullptr)
        {
            if(currentLinePtr->lineText == EXCL40) 
            {
                cout << '\n' << "Press enter to continue...";
                cin.ignore(80, '\n');
            }
            else
            {
                outStream << currentLinePtr->lineText <<endl;
                currentLinePtr = currentLinePtr->next;
            }
        }
        return outStream;
    }


Like the comment says, the compiler is complaining identically about LineNode* and firstLinePtr, saying they're "inaccessible." If anyone can point me in the right direction as to what the issue might be, I'll appreciate it.
Last edited on
I don't see a problem. I had no problems compiling it with VS2010.
Topic archived. No new replies allowed.