Note that there are some explanatory texts on larger screens.

plurals
  1. POMultidimensional array of object in C++ , I can not initialize it!
    primarykey
    data
    text
    <p>Rookie C++ Programmer here again</p> <p>I'm using VC++ VS2008 and making an attempt at creating an array of arrays. All objects I wish to store I want to put on the heap.</p> <p>In the arrays it's all just pointers. </p> <p>Here's some code:</p> <blockquote> <p>Grid.h</p> </blockquote> <pre><code>#include "Tile.h" class Grid { public: Tile* grid_ptr[8][8]; ... ... }; </code></pre> <blockquote> <p>Grid.cpp</p> </blockquote> <pre><code>#include "stdafx.h" #include "Grid.h" ... ... void Grid::Initialize() { for(int i = 0; i &lt; 8; i++) { Grid::grid_ptr[i][0] = new Tile::Tile(10,10); for (int j = 0; j &lt; 8; j++) { Grid::grid_ptr[i][j] = new Tile::Tile(10,10); } } } ... ... } </code></pre> <p>Everything works just fine including the tile construction. It seems like a syntax error seeing as the compiler gives me this</p> <p>Error 1 error C2061: syntax error : identifier '{ctor}'</p> <p>Error 2 error C2061: syntax error : identifier '{ctor}'</p> <p>All the time the same story. This has my entire work bogged down to a halt unfortunatly and I would MUCH Appreciate a solution to this.</p> <p>In short. How do I properly create an array of arrays 8x8 in size filled with pointers referencing their respective tile objects ?</p> <p>Is this even possible or smart to do using memory like that?</p> <p>mind that I did read lots of examples on this, and doing so with integers or other datatypes has been a succes. That however simply isn't want I want allocated</p> <blockquote> <p>Tile.h here and Tile.cpp below</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(unsigned short horizontalDimensions, unsigned short verticalDimensions); ~Tile(); void Update(); void Draw(); }; &gt; Tile.cpp #include "stdafx.h" #include "Tile.h" Tile::Tile() { } Tile::Tile(unsigned short horizontalDimensions, unsigned short verticalDimensions) { } void Tile::Update() { } void Tile::Draw() { } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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