Note that there are some explanatory texts on larger screens.

plurals
  1. POI am trying to create an array of objects inside a header file which is failing (Starting C++ Programmer)
    text
    copied!<p>EDITED BELOW FOR UPDATES!!! Thank you for the help, please by all means point out ALL mistakes , I don't care if it sounds rude or mean or whatever, emo junk. Just give it to me straight so I can understand what is going wrong.</p> <p>Hi everyone!</p> <p>I am a rookie C++ programmer trying to learn and gain some IRL exp for C++.</p> <p>I am attempting the following inside my VC++ (vs2008) compiler:</p> <pre><code>typedef unsigned short USHORT; class Grid { ... public: Grid() { Tile[36]* tileList_ptr; } ... }; </code></pre> <p>In essence, I want to put 36 tiles , slam them into an array nice and tidy on the heap for a 8x8 playfield that never changes in size. Like a chessboard. Refer to them with a pointer, and fiddle with them in the related cpp file if needed.</p> <p>If you aren't laughing by now at this attempt then I probably made a syntax error instead of major design flaw :P</p> <p>Any help would be much appreciated!</p> <p>Thanks in advance</p> <p>EDIT 24/08/2010 13:49 (Time of start)</p> <p>My code is now as following example:</p> <blockquote> <p>The Grid Header file Grid.h:</p> </blockquote> <pre><code>#include "Tile.h" class Grid { //no more typedef used public: Tile grid[8][8]; private: unsigned short selectedItemIndexValue; public: Grid() { Initialize(); } ~Grid(){} void Update(); void FinalizeMove(unsigned short index); void Draw(); private: void Initialize(); //Initializes members }; </code></pre> <blockquote> <p>The Grid.cpp file:</p> </blockquote> <pre><code>#include "stdafx.h" #include "Grid.h" //Not tile , that used to give me a class redefinition error unsigned short selectedItemIndexValue; //No more typedef used void Grid::Update() { //Respond to controller commands } void Grid::FinalizeMove(unsigned short index) { } void Grid::Draw() { } void Grid::Initialize() { for(int i = 0; i &lt; 4; i++) { Grid::grid[i] = new Tile::Tile(10,10); // ATTEMPT AT FILLING ARRAY } } </code></pre> <blockquote> <p>Tile.h file</p> </blockquote> <pre><code>class Tile { public: private: enum TileOccupation { EmptyTile = 0, WhiteSphere = 1, BlackSphere = 2 }; unsigned short horizontalDimensions; unsigned short verticalDimensions; public: Tile(){} ~Tile(){} void Update(); void Draw(); }; </code></pre> <blockquote> <p>Tile.cpp file:</p> </blockquote> <pre><code>#include "stdafx.h" #include "Tile.h" void Tile::Update() { } void Tile::Draw() { } </code></pre> <p>The attempt at filling the array in Grid.cpp is returning via the compiler the following error message: "Error 1 error C2061: syntax error : identifier '{ctor}'"</p> <p>MSDN helped me giving me this:</p> <p>"Compiler Error C2061. The compiler found an identifier where it wasn't expected. Make sure that identifier is declared before you use it."</p> <p>I have failed at analysing it's meaning. What exactly have I done wrong here ? And what other problems are there to be found in my project? All help and comments will be much appreciated. Just assume I know 0% of C++</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload