title: Invalid use of incomplete type "class"
body: <p>I know there has been tons of questions like that, but unfortunately after hours of googling and browsing through all of them, none of the answers I read helped. Therefore I am making my own version of my question. The error message I get is: "error: invalid use of incomplete type ‘std::iterator_traits::value_type {aka class Cell}’" My code:</p>
  
  <p>cell.h</p>
  
  <pre><code>#ifndef CELL_H
  #define CELL_H
  
  #include &lt;QPushButton&gt;
  #include &lt;QMouseEvent&gt;
  #include &lt;vector&gt;
  
  class Padding;
  
  class Cell : public QPushButton
  {
      Q_OBJECT
  
      public:
  
          friend class Padding;
          Cell(int x, int y, Padding* padding, QWidget* parent = 0) : QPushButton(parent), x(x), y(y),
              padding(padding)
          {
              setFixedSize(20, 20);
          }
          Cell(const Cell&amp; object) : QPushButton(), x(object.x), y(object.y), padding(object.padding)
          {
              setFixedSize(20, 20);
          }
          int getX() { return x; };
          int getY() { return y; };
          bool hasMine() { return mine; };
          void setHasMine(bool mine) { this -&gt; mine = mine; };
          bool isFlagged() { return flagged; };
          bool didExplode() { return exploded; };
          bool getHasBeenClicked() { return hasBeenClicked; };
          void clicked();
          ~Cell() {};
          Cell operator=(const Cell&amp; object)
          {
              if(&amp;object == this)
              {
                  return *this;
              }
              padding = object.padding;
              x = object.x;
              y = object.y;
              mine = object.mine;
              flagged = object.flagged;
              exploded = object.exploded;
              hasBeenClicked = object.hasBeenClicked;
              setFixedSize(20, 20);
              return *this;
          }
  
      private:
  
          Padding* padding;
          int x;
          int y;
          bool mine = false;
          bool flagged = false;
          bool exploded = false;
          bool hasBeenClicked = false;
          void mousePressEvent(QMouseEvent* e);
          void rightClicked();
  };
  
  #endif // CELL_H
  </code></pre>
  
  <p>cell.cpp</p>
  
  <pre><code>#include "cell.h"
  #include "padding.h"
  
  void Cell::mousePressEvent(QMouseEvent* event)
  {
      if(event -&gt; button() == Qt::LeftButton)
      {
          clicked();
      }
      else if(event -&gt; button() == Qt::RightButton)
      {
          rightClicked();
      }
  }
  
  void Cell::clicked()
  {
      hasBeenClicked = true;
      // TODO: Set the button frame to flat. DONE.
      setFlat(true);
      // TODO: Make the button not click able. DONE.
      setEnabled(false);
      // TODO: Display appropriate number on the button, or mine and end the game. DONE.
      if(mine)
      {
          // TODO: Send game over signal and end the game.
          //setIcon(QIcon("mine_clicked.png"));
          setText("/");
          exploded = true;
          padding -&gt; gameOver();
      }
      else
      {
          setText(QString::number(padding -&gt; countMinesAround(this)));
      }
      if(padding -&gt; countMinesAround(this) == 0)
      {
          // Trigger chain reaction; uncover many neighboring cells, if they are not mines.
          padding -&gt; triggerChainReactionAround(this);
      }
  }
  
  void Cell::rightClicked()
  {
      if(text() != "f")
      {
          setText("f");
          (padding -&gt; minesLeft)--;
      }
      else
      {
          setText("");
          (padding -&gt; minesLeft)++;
      }
      flagged = !flagged;
  }
  </code></pre>
  
  <p>padding.h</p>
  
  <pre><code>#ifndef PADDING_H
  #define PADDING_H
  
  #include &lt;QWidget&gt;
  #include &lt;QGridLayout&gt;
  #include &lt;vector&gt;
  
  class Cell;
  
  class Padding : public QWidget
  {
      Q_OBJECT
  
      public:
  
          friend class Cell;
  
          enum class Difficulty
          {
              Beginner,
              Intermediate,
              Advanced,
              Custom
          };
  
          Padding(QWidget* parent = 0);
          void newGame();
          void gameOver();
          void setLevel(Padding::Difficulty difficulty) { this -&gt; difficulty = difficulty; };
          void setPaddingHeight(int height) { paddingHeight = height; };
          void setPaddingWidth(int width) { paddingWidth = width; };
          void setMines(int mines) { this -&gt; mines = mines; };
          int getMinesLeft() { return minesLeft; };
          ~Padding() {};
  
      private:
  
          struct DifficultyLevelsProperties
          {
              struct BeginnerProperties
              {
                  const int PADDING_HEIGHT = 9;
                  const int PADDING_WIDTH = 9;
                  const int MINES = 10;
              } Beginner;
  
              struct IntermediateProperties
              {
                  const int PADDING_HEIGHT = 16;
                  const int PADDING_WIDTH = 16;
                  const int MINES = 40;
              } Intermediate;
  
              struct AdvancedProperties
              {
                  const int PADDING_HEIGHT = 16;
                  const int PADDING_WIDTH = 40;
                  const int MINES = 99;
              } Advanced;
          } LevelProperties;
  
          Difficulty difficulty = Difficulty::Beginner;
          int paddingHeight;
          int paddingWidth;
          int mines;
          // Mines that are not flagged.
          int minesLeft;
          // Time in seconds since the game was started.
          int secondsSinceStart;
          std::vector&lt;Cell&gt; cells;
          QGridLayout* paddingLayout;
          const int CELLS_HEIGHT = 20;
          const int CELLS_WIDTH = 20;
          int countMinesAround(Cell*);
          void triggerChainReactionAround(Cell*);
          void updateSecondsSinceStart();
  };
  
  #endif // PADDING_H
  </code></pre>
  
  <p>padding.cpp</p>
  
  <pre><code>#include "padding.h"
  #include &lt;QGridLayout&gt;
  #include &lt;QTimer&gt;
  #include &lt;QTime&gt;
  #include &lt;QDebug&gt;
  #include "cell.h"
  
  Padding::Padding(QWidget* parent) : QWidget(parent)
  {
      newGame();
      paddingLayout = new QGridLayout(this);
      paddingLayout -&gt; setSpacing(0);
  }
  
  void Padding::newGame()
  {
      if(difficulty == Padding::Difficulty::Beginner)
      {
          paddingHeight = LevelProperties.Beginner.PADDING_HEIGHT;
          paddingWidth = LevelProperties.Beginner.PADDING_WIDTH;
          mines = LevelProperties.Beginner.MINES;
      }
      else if(difficulty == Padding::Difficulty::Intermediate)
      {
          paddingHeight = LevelProperties.Intermediate.PADDING_HEIGHT;
          paddingWidth = LevelProperties.Intermediate.PADDING_WIDTH;
          mines = LevelProperties.Intermediate.MINES;
      }
      else if(difficulty == Padding::Difficulty::Advanced)
      {
          paddingHeight = LevelProperties.Advanced.PADDING_HEIGHT;
          paddingWidth = LevelProperties.Advanced.PADDING_WIDTH;
          mines = LevelProperties.Advanced.MINES;
      }
      minesLeft = mines;
      cells.clear();
      for(int i = 0; i &lt; paddingHeight; i++)
      {
          for(int j = 0; j &lt; paddingWidth; j++)
          {
              // TODO: Use smart pointers instead of raw pointers.
              Cell* cell = new Cell(j + 1, i + 1, this);
              cells.push_back(*cell);
              delete cell;
          }
      }
      qsrand(QTime::currentTime().msec());
      for(int i = 0; i &lt; mines; i++)
      {
          // TODO: Fix the randomness of the numbers. DONE.
          cells[qrand() % (paddingHeight * paddingWidth) + 1].setHasMine(true);
      }
      for(int i = 0; i &lt; cells.size(); i++)
      {
          paddingLayout -&gt; addWidget(&amp;cells[i], cells[i].getY(), cells[i].getX());
      }
  }
  
  void Padding::gameOver()
  {
      for(int i = 0; i &lt; cells.size(); i++)
      {
          cells[i].setEnabled(false);
          if((cells[i].hasMine()) &amp;&amp; (!cells[i].getHasBeenClicked()))
          {
              cells[i].clicked();
          }
      }
  }
  
  int Padding::countMinesAround(Cell*)
  {
      int minesCounter = 0;
      for(int i = 0; i &lt; cells.size(); i++)
      {
          qDebug() &lt;&lt; QString::number(cells[i].getX());
          if(((x - cells[i].getX() == 0) || (x - cells[i].getX() == 1) || (x -
              cells[i].getX() == -1)) &amp;&amp; ((y - cells[i].getY() == 0) || (y -
              cells[i].getY() == 1) || (y - cells[i].getY() == -1)) &amp;&amp;
              (cells[i].hasMine()))
          {
              minesCounter++;
          }
      }
      return minesCounter;
  }
  
  void Padding::triggerChainReactionAround(Cell*)
  {
      for(int i = 0; i &lt; cells.size(); i++)
      {
          if(((x - cells[i].getX() == 0) || (x - cells[i].getX() == 1) || (x -
              cells[i].getX() == -1)) &amp;&amp; ((y - cells[i].getY() == 0) || (y -
              cells[i].getY() == 1) || (y - cells[i].getY() == -1)) &amp;&amp;
              (!cells[i].getHasBeenClicked()))
          {
              cells[i].clicked();
          }
      }
  }
  </code></pre>
  
  <p>Sorry for how long the whole thing, but I could not shorten it as I can't locate what causes the error. Also please ignore any TODO's or any lines that are commented out and I forgot to delete them. Please help!</p>