How do I put this statement in the class definition

T

Tony Johansson

Hello!!

I have these two statements
"typedef const char *enum_txt[];"
"enum_txt phase_tab =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERRELEASE","SPACE"};"

It's no problem to put the first statement "typedef const char *enum_txt[];"
for example the public section.in the definition of the class but how do I
put
this statement "enum_txt phase_tab =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERRELEASE","SPACE"};"
is the class definition because when I do I get compile error.

//Tony
 
A

angelo

Tony said:
Hello!!

I have these two statements
"typedef const char *enum_txt[];"
"enum_txt phase_tab =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERRELEASE","SPACE"};"

It's no problem to put the first statement "typedef const char *enum_txt[];"
for example the public section.in the definition of the class but how do I
put
this statement "enum_txt phase_tab =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERRELEASE","SPACE"};"
is the class definition because when I do I get compile error.

//Tony
Declare them as static member of the class and define while initializing
it outside the class definition.
 
J

John Harrison

Tony Johansson said:
Hello!!

I have these two statements
"typedef const char *enum_txt[];"
"enum_txt phase_tab =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERRELEASE","SPACE"};"

It's no problem to put the first statement "typedef const char
*enum_txt[];" for example the public section.in the definition of the
class but how do I put
this statement "enum_txt phase_tab =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERRELEASE","SPACE"};"
is the class definition because when I do I get compile error.

//Tony

You can't but you don't need to.

I guess you're looking for something like this

class X
{
public:
static const char* const phase_tab[];
};

const char* const X::phase_tab[] =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERRELEASE","SPACE"};

No typedef necessary.

john
 
A

angelo

John said:
I have these two statements
"typedef const char *enum_txt[];"
"enum_txt phase_tab =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERRELEASE","SPACE"};"
You can't but you don't need to.

I guess you're looking for something like this

class X
{
public:
static const char* const phase_tab[];
};

const char* const X::phase_tab[] =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERRELEASE","SPACE"};

No typedef necessary.

john

Oh i see, i didn't notice the typedef is for the definition. Then
actually he can just write

I guess you're looking for something like this

class X
{
public:
static const char* const phase_tab[];
};

typedef const char *enum_txt[];
enum_txt X::phase_tab =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERRELEASE","SPACE"};

which is more readable
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top