title: C++ How to Access Nested Class Ported from Java
body: <p>I have been recently working on a project that includes porting TONS of Java over to C++. The conversion isn't to hard with Qt as I only have to change some of the 'ways' that the code works to cooperate with Qt/C++ classes. Only a few issues though.</p>
  
  <p>I have a file called <code>constants.h</code> this is a normal header file with a top-level class of, you guessed it, <code>Constants</code>. Nested in there are many other classes. I want to be able to access a nested class from that top-level class. Such as: accessing <code>ErrorCode</code> from <code>Constants</code>. I have followed a few thread but I am probably looking in all the wrong corners. Here is my code:</p>
  
  <p>Interface.cpp (MainWindow):</p>
  
  <pre><code>#include "interface.h"
  #include "ui_interface.h"
  #include &lt;QDebug&gt;
  #include "constants.h"
  
  Interface::Interface(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::Interface)
  {
      ui-&gt;setupUi(this);
      //Method 1:
      //Constants::ErrorCode(QStringList list);
  
      //Method 2:
      //Constants con;
      //con.ErrorCode er = con.ErrorCode(QStringList list);
      //or
      //con::ErrorCode er = con::ErrorCode(QStringList list);
  }
  
  Interface::~Interface()
  {
      delete ui;
  }
  </code></pre>
  
  <p>Constants.h (Classes)</p>
  
  <pre><code>class Constants
  {
  public:
  class ErrorCode : Localizable
      {
          QStringList ACCESS_DENIED = QStringList() &lt;&lt; "ad" &lt;&lt; "Access denied.";
          QStringList ALREADY_STARTED = QStringList() &lt;&lt; "as" &lt;&lt; "The game has already started.";
          QStringList ALREADY_STOPPED = QStringList() &lt;&lt; "aS" &lt;&lt; "The game has already stopped.";
          QStringList BAD_OP = QStringList() &lt;&lt; "bo" &lt;&lt; "Invalid operation.";
          QStringList BAD_REQUEST = QStringList() &lt;&lt; "br" &lt;&lt; "Bad request.";
          QStringList BANNED = QStringList() &lt;&lt; "B&amp;" &lt;&lt; "Banned.";
          QStringList CANNOT_JOIN_ANOTHER_GAME = QStringList() &lt;&lt; "cjag" &lt;&lt; "You cannot join another game.";
          QStringList CARDCAST_INVALID_ID = QStringList() &lt;&lt; "cii" &lt;&lt; "Invalid Cardcast ID. Must be exactly 5 characters.";
          QStringList DO_NOT_HAVE_CARD = QStringList() &lt;&lt; "dnhc" &lt;&lt; "You don't have that card.";
          QStringList GAME_FULL = QStringList() &lt;&lt; "gf" &lt;&lt; "That game is full. Join another.";
          QStringList INVALID_CARD = QStringList() &lt;&lt; "ic" &lt;&lt; "Invalid card specified.";
          QStringList INVALID_GAME = QStringList() &lt;&lt; "ig" &lt;&lt; "Invalid game specified.";
          QStringList INVALID_NICK = QStringList() &lt;&lt; "in" &lt;&lt; "Nickname must contain only upper and lower case letters, "
                                         "numbers, or underscores, must be 3 to 30 characters long, and must not start with a "
                                         "number.";
          QStringList MESSAGE_TOO_LONG = QStringList() &lt;&lt; "mtl" &lt;&lt; "Messages cannot be longer than 200 characters.";
          QStringList NICK_IN_USE = QStringList() &lt;&lt; "niu" &lt;&lt; "Nickname is already in use.";
          QStringList NO_CARD_SPECIFIED = QStringList() &lt;&lt; "ncs" &lt;&lt; "No card specified.";
          QStringList NO_GAME_SPECIFIED = QStringList() &lt;&lt; "ngs" &lt;&lt; "No game specified.";
          QStringList NO_MSG_SPECIFIED = QStringList() &lt;&lt; "nms" &lt;&lt; "No message specified.";
          QStringList NO_NICK_SPECIFIED = QStringList() &lt;&lt; "nns" &lt;&lt; "No nickname specified.";
          QStringList NO_SESSION = QStringList() &lt;&lt; "ns" &lt;&lt; "Session not detected. Make sure you have cookies enabled.";
          QStringList NO_SUCH_USER = QStringList() &lt;&lt; "nsu" &lt;&lt; "No such user.";
          QStringList NOT_ADMIN = QStringList() &lt;&lt; "na" &lt;&lt; "You are not an administrator.";
          /*QStringList NOT_ENOUGH_CARDS = QStringList() &lt;&lt; "nec" &lt;&lt; "You must add card sets containing at least "
                                             + Game.MINIMUM_BLACK_CARDS + " black cards and " + Game.MINIMUM_WHITE_CARDS_PER_PLAYER
                                             + " times the player limit white cards.";*/
          QStringList NOT_ENOUGH_PLAYERS = QStringList() &lt;&lt; "nep" &lt;&lt; "There are not enough players to start the game.";
          QStringList NOT_GAME_HOST = QStringList() &lt;&lt; "ngh" &lt;&lt; "Only the game host can do that.";
          QStringList NOT_IN_THAT_GAME = QStringList() &lt;&lt; "nitg" &lt;&lt; "You are not in that game.";
          QStringList NOT_JUDGE = QStringList() &lt;&lt; "nj" &lt;&lt; "You are not the judge.";
          QStringList NOT_REGISTERED = QStringList() &lt;&lt; "nr" &lt;&lt; "Not registered. Refresh the page.";
          QStringList NOT_YOUR_TURN = QStringList() &lt;&lt; "nyt" &lt;&lt; "It is not your turn to play a card.";
          QStringList OP_NOT_SPECIFIED = QStringList() &lt;&lt; "ons" &lt;&lt; "Operation not specified.";
          QStringList RESERVED_NICK = QStringList() &lt;&lt; "rn" &lt;&lt; "That nick is reserved.";
          QStringList SERVER_ERROR = QStringList() &lt;&lt; "serr" &lt;&lt; "An error occured on the server.";
          QStringList SESSION_EXPIRED = QStringList() &lt;&lt; "se" &lt;&lt; "Your session has expired. Refresh the page.";
          QStringList TOO_FAST = QStringList() &lt;&lt; "tf" &lt;&lt; "You are chatting too fast. Wait a few seconds and try again.";
          QStringList TOO_MANY_GAMES = QStringList() &lt;&lt; "tmg" &lt;&lt; "There are too many games already in progress. Either join "
                                           "an existing game, or wait for one to become available.";
          QStringList TOO_MANY_USERS = QStringList() &lt;&lt; "tmu" &lt;&lt; "There are too many users connected. Either join another server, or "
                                           "wait for a user to disconnect.";
          QStringList WRONG_PASSWORD = QStringList() &lt;&lt; "wp" &lt;&lt; "That password is incorrect.";
      private:
          QString code;
          QString message;
          ErrorCode(const QStringList dataList)
          {
              this-&gt;code = dataList[0];
              this-&gt;message = dataList[1];
          }
      public:
          virtual QString toString()
          {
              return code;
          }
          virtual QString getString()
          {
              return message;
          }
      };
  };
  </code></pre>
  
  <p>Any help is greatly appreciated! Thank you.</p>