N
NvrBst
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::Myclass() {
m_navi = { {"1"} };
}
MyClass:~MyClass() {
}
----------
1. I get an "expected ';' before '{' token" error at the "m_navi = {"
line. I also get an "uninitalized member "Myclass::t" error.
2. If I change "m_navi = {" to "MyClass::m_navi = {" 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.cpp" 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.
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::Myclass() {
m_navi = { {"1"} };
}
MyClass:~MyClass() {
}
----------
1. I get an "expected ';' before '{' token" error at the "m_navi = {"
line. I also get an "uninitalized member "Myclass::t" error.
2. If I change "m_navi = {" to "MyClass::m_navi = {" 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.cpp" 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.