In my Dev C++, I am trying to create a 2D Array class that acts like a Grid. But one of the problem is I am unsure what do for the constructor.
When I try to compile, I get the following errors: In constructor 'Grid::Grid(int,int)': 'sqaures' is not a type 'yPos' cannot appear in a constant-expression [Build Error] [grid.o] Error 1
Here is the Header File:
#ifndef GRID_H
#define GRID_H
using namespace std;
class Grid
{
public:
Grid(int xPos, int yPos);
// Constructor
// POST: Creates the squares of grid; (x,y) coordinates
private:
int squares;
//2D Array
//the squares; (x,y) coordinates of the grids
};
#endif
And heres the .cpp file for the functions of grid.h
#include <iostream>
#include "grid.h"
using namespace std;
Grid::Grid(int xPos, int yPos)
{
squares = new squares[xPos][yPos];
//Trying to make squares into a 2D array, and turn the values into the arguments
//into the the x,y coordinates
}
My constructor in the .cpp files doesn't work and I'm unsure what to do. Does anyone have any solutions?