473,795 Members | 2,865 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Const Multi-Dimentional Array Member Variable

I'd like to do something like this but having a problem with the
proper syntax in the constructor, maybe someone knows the correct
syntax?

---MyClass.h---
#ifndef MYCLASS_H_
#define MYCLASS_H_

class MyClass {
public:
MyClass();
virtual ~MyClass();
private:
const char* const m_navi[1][1];
};

#endif /*MYMENU_H_*/
----------

---MyClass.cpp---
#include "MyClass.h"

MyClass::Myclas s() {
m_navi = { {"1"} };
}

MyClass:~MyClas s() {
}
----------
1. I get an "expected ';' before '{' token" error at the "m_navi = {"
line. I also get an "uninitaliz ed member "Myclass::t " error.
2. If I change "m_navi = {" to "MyClass::m_nav i = {" I get the same
errors as "1.".
3. I've tried declaring it in the header file directly (const char*
const m_navi[1][1] = { {"1"} };) and get an "a brace-enclosed
initializer is not allowed here before '{' token" error.
4. I've tried making it static (static const char* const m_navi[1][1]
= { {"1"} };) and get the same errors as "3."
5. If I move the (const char* const m_navi[1][1] = { {"1"} };) into
the "main.cpp" file (above the "int main() {" line) then it compiles
fine and I can use it fine in the main function.

Question: Whats the proper way to assign the (const char* const m_navi
[1][1]) inside the constructor? Assuming the above "MyClass.h" and
"MyClass.cp p" files? Thanks

Note: The member variable can be static if that makes it easier; the
data inside "m_navi" never changes once it is set, and there is only
one instance of "MyClass" ever created; I would like to set the value
inside the constructor though if possible since values in "m_navi"
potentially gets updated between builds, so I'd only have to change
the ".cpp" file, but this isn't 100% nessisary.

I'm using Eclipse 3.2.2, on a Ubuntu 8.10 Machine. g++ Version
"4.2.4". Thanks.
Nov 12 '08 #1
3 3508
"NvrBst" wrote:
>
I'd like to do something like this but having a problem with the
proper syntax in the constructor, maybe someone knows the correct
syntax?

---MyClass.h---
#ifndef MYCLASS_H_
#define MYCLASS_H_

class MyClass {
public:
MyClass();
virtual ~MyClass();
private:
const char* const m_navi[1][1];
};

#endif /*MYMENU_H_*/
----------

---MyClass.cpp---
#include "MyClass.h"

MyClass::Myclas s() {
m_navi = { {"1"} };
}

MyClass:~MyClas s() {
}
----------
1. I get an "expected ';' before '{' token" error at the "m_navi = {"
line. I also get an "uninitaliz ed member "Myclass::t " error.
2. If I change "m_navi = {" to "MyClass::m_nav i = {" I get the same
errors as "1.".
3. I've tried declaring it in the header file directly (const char*
const m_navi[1][1] = { {"1"} };) and get an "a brace-enclosed
initializer is not allowed here before '{' token" error.
4. I've tried making it static (static const char* const m_navi[1][1]
= { {"1"} };) and get the same errors as "3."
5. If I move the (const char* const m_navi[1][1] = { {"1"} };) into
the "main.cpp" file (above the "int main() {" line) then it compiles
fine and I can use it fine in the main function.

Question: Whats the proper way to assign the (const char* const m_navi
[1][1]) inside the constructor? Assuming the above "MyClass.h" and
"MyClass.cp p" files? Thanks

Note: The member variable can be static if that makes it easier; the
data inside "m_navi" never changes once it is set, and there is only
one instance of "MyClass" ever created; I would like to set the value
inside the constructor though if possible since values in "m_navi"
potentially gets updated between builds, so I'd only have to change
the ".cpp" file, but this isn't 100% nessisary.

I'm using Eclipse 3.2.2, on a Ubuntu 8.10 Machine. g++ Version
"4.2.4". Thanks.
You have a typo in your source ("Myclass" vs. "MyClass") :-)
One of the possible solutions would be the following:

// in header file:
class MyClass
{
public:
MyClass() {}
virtual ~MyClass() {}
private:
static const char* const m_navi[1][1];
};

// the following must not be placed in the header file:
const char* const MyClass::m_navi[1][1] = { { "1" } }; // static init

int main()
{
MyClass m;
return 0;
}

Nov 13 '08 #2
On Nov 12, 7:15*pm, "Adem" <for-usenet...@alice who.comwrote:
"NvrBst" wrote:
I'd like to do something like this but having a problem with the
proper syntax in the constructor, maybe someone knows the correct
syntax?
---MyClass.h---
#ifndef MYCLASS_H_
#define MYCLASS_H_
class MyClass {
public:
* *MyClass();
* *virtual ~MyClass();
private:
* *const char* const m_navi[1][1];
};
#endif /*MYMENU_H_*/
----------
---MyClass.cpp---
#include "MyClass.h"
MyClass::Myclas s() {
* *m_navi = { {"1"} };
}
MyClass:~MyClas s() {
}
----------
1. *I get an "expected ';' before '{' token" error at the "m_navi ={"
line. *I also get an "uninitaliz ed member "Myclass::t " error.
2. *If I change "m_navi = {" to "MyClass::m_nav i = {" I get the same
errors as "1.".
3. *I've tried declaring it in the header file directly (const char*
const m_navi[1][1] = { {"1"} };) and get an "a brace-enclosed
initializer is not allowed here before '{' token" error.
4. I've tried making it static (static const char* const m_navi[1][1]
= { {"1"} };) and get the same errors as "3."
5. If I move the (const char* const m_navi[1][1] = { {"1"} };) into
the "main.cpp" file (above the "int main() {" line) then it compiles
fine and I can use it fine in the main function.
Question: Whats the proper way to assign the (const char* const m_navi
[1][1]) inside the constructor? *Assuming the above "MyClass.h" and
"MyClass.cp p" files? *Thanks
Note: The member variable can be static if that makes it easier; the
data inside "m_navi" never changes once it is set, and there is only
one instance of "MyClass" ever created; I would like to set the value
inside the constructor though if possible since values in "m_navi"
potentially gets updated between builds, so I'd only have to change
the ".cpp" file, but this isn't 100% nessisary.
I'm using Eclipse 3.2.2, on a Ubuntu 8.10 Machine. *g++ Version
"4.2.4". *Thanks.

You have a typo in your source ("Myclass" vs. "MyClass") *:-)
One of the possible solutions would be the following:

// in header file:
class MyClass
* {
* * public:
* * * MyClass() {}
* * * virtual ~MyClass() {}
* * private:
* * * static const char* const m_navi[1][1];
* *};

// the following must not be placed in the header file:
const char* const MyClass::m_navi[1][1] = { { "1" } }; * // static init

int main()
* {
* * MyClass m;
* * return 0;
* }
Thank you :) That worked dandily. I think I got mixed up since I
kept trying to do it in either the header file, or the ctor. Thanks
once more.
Nov 13 '08 #3
Another Initialization Question if Possible; Kind of relates to the
top. Is there a short hand way to initializat during a new operator?
For example I can do the following:
----- CAN DO -----
const char** FSETUP[2] = {
new const char*[2],
new const char*[4]
}
int main() {
FSETUP[0][0] = "T1";
FSETUP[0][1] = "T2";
//ETC
return 0;
}

----- WOULD LIKE TO DO BUT ERRORS -----
const char** FSETUP[2] = {
new const char*[2] {"T1","T2"},
new const char*[4] {"F1","F2","F3" ,"F4"}
}
int main() {
return 0;
}
It has to stay a jagged array. All examples online I find intalizae
the jagged array the long way, is there a short way to set it when it
is being initialized? The error is "Expected ';' before '{'")
Nov 13 '08 #4

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

Similar topics

4
2424
by: Neil Zanella | last post by:
Hello, I would be very interested in knowing how the following C++ multi-instance singleton (AKA Borg) design pattern based code snippet can be neatly coded in Python. While there may be somewhat unusual places where multi-instance singleton is more useful than plain singleton, it seems to me that the former leads to less coding, so unless I can somehow package the singleton pattern in a superclass (so I don't have to code it...
5
8504
by: PEK | last post by:
I need some code that convert a multi-byte string to a Unicode string, and Unicode to multi-byte. I work mostly in Windows and know how to solve it there, but I would like to have some platform independent code too. I have tried with mbtowcs/wctombs but I'm not satisfied with the result. If wctombs finds a character that can't be converted it return -1, and stops. I would like to replace such of characters with some special character...
2
2199
by: Victor Nazarov | last post by:
Assuming my locale has enough info about codepage and multi-byte charecters, how should I compare (collate) multi-byte strings (strings of multi-byte charecters with zero-byte at the end) in ISO C99? Thanks in advance Vir
20
17362
by: Chris | last post by:
Hi, can you define const-functions in C# as in C++ ? for example (C++-code) : int Cube :: GetSide() const { return m_side; }
5
6001
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a TIFF to several PNG files this causes a problem, becuase the resulting image is (the page to the far left and a lot of black space surrounding it and a filesize that is larger than needed. Any ideas?
4
5596
by: Steve | last post by:
Hi all, I don't want to use the datagrid if I don't have to. Is there a way to setup a ListBox to have more than one checkbox column? I need something like this | Include || Set as Default || Other columns... | asdasdasd digity-digity!
11
6258
by: rossum | last post by:
I want to declare a const multi-line string inside a method, and I am having some problems using Environment.NewLine. I started out with: class foo { public void PrintStuff() { const string multiline = "The first line." + Environment.NewLine +
4
2110
by: Bob Altman | last post by:
If I create a new Win32 Console project (unmanaged C++, Visual Studio 2005), and add the following to the main program: // Add this above the main routine #include <windows.h // Add this at the top of the file // Add this to the main routine MessageBox(NULL, "A", "B", MB_OK); The compiler (Visual Studio 2005) complains that it can't convert parameter
1
1654
by: Ali Karaali | last post by:
Hello group ! I have a class interface (as .h ) but i don't have this class's source file (as .cpp ). So i can't reach the source file.. class ServerBase { public : virtual void vfunc() const; void nvfunc() const; ~ServerBase();
3
3268
by: 6afraidbecause789 | last post by:
If able, can someone please help make a Where clause that strings together IDs in a multi-select listbox AND includes a date range. I wasn’t thinking when I used the code below that strings together the IDs of Clients from a multi-select listbox in an unbound text field, txtCriteria, on a form that is used to pick different reports. It appears that I now have so many clients that I’ve reached the 255 character limit in the txtCriteria...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10213
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...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
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
7538
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
6780
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();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.