Unable to access nested class. Invalid use of class : <p>I'm getting error when I'm trying to create a nested class and access a function in it. I've been trying to fix it for hours but to no success.</p>

<blockquote>
  <p>error: invalid use of 'class sqlInterface::connectToSQL'  fhm.connectToSQL.connect();</p>
</blockquote>

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

<p>sqlTest.cpp:</p>

<pre><code>#include &lt;stdlib.h&gt;
#include &lt;iostream&gt;
#include "mySQLinterface.h"


sqlInterface fhm;

int main(int argc, char const *argv[])
{

    fhm.connectToSQL.connect();

    return 0;

}
</code></pre>

<p>mySQLinterface.h:</p>

<pre><code>#ifndef MYSQLINTERFACE_H
#define MYSQLINTERFACE_H

#include &lt;mysql_connection.h&gt;


class sqlInterface {

    public:
        class connectToSQL{
            public:
                void connect(void);
        };
};

#endif
</code></pre>

<p>mySQLinterface.cpp:</p>

<pre><code>#include "mySQLinterface.h"
#include &lt;mysql_connection.h&gt;
#include &lt;mysql_driver.h&gt;

#include &lt;exception.h&gt;
#include &lt;resultset.h&gt;
#include &lt;statement.h&gt;


#include &lt;iostream&gt;



void sqlInterface::connectToSQL::connect(void){
    sql::mysql::MySQL_Driver *driver;
    sql::Connection *con;

    try{
    driver = sql::mysql::get_mysql_driver_instance();
    con = driver-&gt;connect("tcp://172.17.0.2:3306", "USERNAME", "PASSWORD");

    }
    catch(std::exception &amp;e){
        cout &lt;&lt; "CONNECTION ERROR: " &lt;&lt; e.what() &lt;&lt; endl;
    }

    bool alive = con-&gt;isValid();
    std::cout &lt;&lt; "Valid connection: " &lt;&lt; alive &lt;&lt; std::endl;


    delete con;


}
</code></pre>
