473,796 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble Declaring 3D Array in Header File

Hi,
I am relatively new to programming C++ and I am writing a small program
in which I am using a 3D array of type int. The 3D array is a member
of class GameBoard, which I have defined in the GameBoard.h header file
as follows:

class GameBoard {

//function prototypes
public:
GameBoard();
int getMovePeg();
void readMovePeg();
void readDestPeg();
void makeMove();
bool gameOverCheck() ;
void endGame();
void displayBoard();
private:
bool peg;
int movePeg, destPeg, jumpPeg, movesTaken, leftPegs;

//HERE IS THE DECLARATION FOR THE ARRAY
int holes[15][5][2];

void initHoles();
string printHole(int);
};

I then
#include "GameBoard. h"
in the GameBoard.cpp file. Then I try to do this with the array:

GameBoard::hole s = {{{0,0},{1,3},{ 2,5},{0,0},{0,0 }}, //hole 0

{{0,0},{3,6},{4 ,8},{0,0},{0,0} }, //hole 1
{{0,0},{4,7},{5 ,9},{0,0},{0,0} }, //hole 2
{{0,0},{1,0},{4 ,5},{6,10},{7,1 2}}, //hole 3
{{0,0},{7,11},{ 8,13},{0,0},{0, 0}}, //hole 4
{{0,0},{2,0},{4 ,3},{8,12},{9,1 4}}, //hole 5
{{0,0},{3,1},{7 ,8},{0,0},{0,0} }, //hole 6
{{0,0},{4,2},{8 ,9},{0,0},{0,0} }, //hole 7
{{0,0},{4,1},{7 ,6},{0,0},{0,0} }, //hole 8
{{0,0},{5,2},{8 ,7},{0,0},{0,0} }, //hole 9
{{0,0},{6,3},{1 1,12},{0,0},{0, 0}}, //hole 10
{{0,0},{7,4},{1 2,13},{0,0},{0, 0}}, //hole 11
{{0,0},{7,3},{8 ,5},{11,10},{13 ,14}}, //hole 12
{{0,0},{8,4},{1 2,11},{0,0},{0, 0}}, //hole 13
{{0,0},{9,5},{1 3,12},{0,0},{0, 0}}}; //hole 14

I get this error:

"error C2761: 'int GameBoard::hole s[15][5][2]' : member function
redeclaration not allowed"

What am I doing wrong? I have tried everything I could think of to get
this array to work. Thanks in advance for any help that anyone can
offer! If I need to provide any more code or explanation, please let
me know.

Brian

Jul 21 '06 #1
2 1957
free2klim wrote:
Hi,
y:
>
int GameBoard::hole s = {{{0,0},{1,3},{ 2,5},{0,0},{0,0 }},
^I guess you forgot the "int" before the GameBoard there?
"error C2761: 'int GameBoard::hole s[15][5][2]' : member function
redeclaration not allowed"
g++ often has more insightful error messages:

ref.cc:27: error: `int GameBoard::hole s' is not a static member of
`class GameBoard'

Adding static to the declaration within the class (.h), g++ reports:

ref.cc:27: error: conflicting declaration 'int GameBoard::hole s'
ref.cc:20: error: 'GameBoard::hol es' has a previous declaration as `int
GameBoard::hole s[15][5][2]'

So, the types mismatch, we'll have to add the [][][] to the declaration
too.
I ended up with:

class GameBoard{
...
int holes[15][5][2];
};
....
int GameBoard::hole s[15][5][2] = {{{0,0},{1,3},{ 2,5},{0,0},{0,0 }},
which compiles.

Jul 21 '06 #2

jo******@gmail. com wrote:
g++ often has more insightful error messages:

ref.cc:27: error: `int GameBoard::hole s' is not a static member of
`class GameBoard'

Adding static to the declaration within the class (.h), g++ reports:

ref.cc:27: error: conflicting declaration 'int GameBoard::hole s'
ref.cc:20: error: 'GameBoard::hol es' has a previous declaration as `int
GameBoard::hole s[15][5][2]'

So, the types mismatch, we'll have to add the [][][] to the declaration
too.

Thank you very much! That worked! I ended up with this, just like you
said:

class GameBoard{
...
static int holes[15][5][2];
};
....
int GameBoard::hole s[15][5][2] = {{{0,0},{1,3},{ 2,5},{0,0},{0,0 }},

Jul 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2262
by: Pegboy | last post by:
I am having trouble with malloc() again for a PC app I am developing. The method of the suspicious line of code seems to be Ok on a embedded platform, but not with the PC platform. The embedded platform uses a different compiler. I feel like I'm overlooking a very simple problem, but I can't see it. I would appreciate any help. Thank you. I am trying to allocate memory for a structure of type NAT_S which contains a pointer to a...
2
1486
by: nospam_timur | last post by:
I'm writing a Linux device driver that needs to compile with several different Linux versions. In my code, I need to reference certain functions by their address alone. Something like this: int myfunc(char *x); if (memory_test == myfunc) .... In other words, I don't care about the return values or the parameters of myfunc(), I just need to reference it.
2
1653
by: Zardoz | last post by:
I've created a new header file in which one will find : #using <mscorlib.dll> using namespace System; __gc class G { public: int k; int sum(int){return 0;}
10
2605
by: athanasios.silis | last post by:
Hello everyone, i am attempting to make a structure #include "globalVars.h" struct myStruct{ int offset; unsigned char uChars; } saveVars, getVars;
0
1722
grassh0pp3r
by: grassh0pp3r | last post by:
Hello, I'm trying to make a very simple comments page on my site using PHP and am having problems somewhere. I am very new to PHP. I was able to create one that works with comments appended, but I want the latest comment to be on top, and that's where I'm running into trouble. Since I know very little about PHP, I thought I was clever in what I came up with. I think it can work if I get the coding right. Let me know if my logic is wrong. I'm...
1
2449
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are of different lengths (e.g. usually between 25 and 45 rows. The columns in each file have the same length). The text files have been numbered sequentially e.g. cb0, cb1, cb2 and so on. I would like to read the data from each text file into...
9
5619
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return String.Format("'{0}'", value) End Function Basically, I just want to surround each value with single quotes. However, I am having trouble getting this to work using the System.Array.ForEach method. This may be partially because I am not very...
8
4596
by: nguillot | last post by:
Hello. If I have the following classes: class B {}; typedef B tB; if A is: class A
5
13384
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10455
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10228
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10173
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.