How to use Nested Classes properly in C++?
<p>I am learning C++, and I'm trying to learn more about using the friend keyboard.</p>

<p>However, I am having trouble using nested classes in my Header file.</p>

<p>I know that header files should only be used for declarations but I didnt want to include a cpp file with it so I just used a header file to declare and build.</p>

<p>Anways, I have a main.cpp file that I want strictly to be used for creating objects of classes and accessing its functions.</p>

<p>However, I dont know exactly how to create the FriendFunctionTest function in my header file to where I can access it in my main.cpp source file using the header Class object because I'm trying to understand the "friend" keyword.</p>

<p>Here is my header code:</p>

<pre><code>#ifndef FRIENDKEYWORD_H_
#define FRIENDKEYWORD_H_

using namespace std;

class FriendKeyword
{
    public:
        FriendKeyword()
        {//default constructor setting private variable to 0
            friendVar = 0;
        }
    private:
        int friendVar;

    //keyword "friend" will allow function to access private members
    //of  FriendKeyword class
    //Also using &amp; in front of object to "reference" the object, if
    //using the object itself, a copy of the object will be created
    //instead of a "reference" to the object, i.e. the object itself
    friend void FriendFunctionTest(FriendKeyword &amp;friendObj);
};

void FriendFunctionTest(FriendKeyword &amp;friendObj)
{//accessing the private member in the FriendKeyword class
    friendObj.friendVar = 17;

    cout &lt;&lt; friendObj.friendVar &lt;&lt; endl;
}

#endif /* FRIENDKEYWORD_H_ */
</code></pre>

<p>In my main.cpp file, I wanted to do something like this:</p>

<pre><code>FriendKeyword keyObj1;
FriendKeyword keyObj2;
keyObj1.FriendFunctionTest(keyObj2);
</code></pre>

<p>But obviously its not going to work since the main.cpp cant find the FriendFunctionTest function in the header file.</p>

<p>How do I fix this issue?</p>

<p>And I apologize again, I'm just trying to learn C++ online.</p>
