By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,475 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Where in the class definition should these be put

P: n/a
Hello!

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

where in the class definition should these be put.

What I think is that this statement "typedef const char *enum_txt[];"
must be put in the header file outside of the class definition and this
statement "enum_txt phase_tab
={"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTER RELEASE","SPACE"};"
must be put in the implementation file outside of any functionmethod.

//Tony
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Tony Johansson wrote:
I have these two statements
typedef const char *enum_txt[];
and
enum_txt phase_tab
={"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTER RELEASE","SPACE"};

where in the class definition should these be put.

What I think is that this statement "typedef const char *enum_txt[];"
must be put in the header file outside of the class definition and this
statement "enum_txt phase_tab
={"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTER RELEASE","SPACE"};"
must be put in the implementation file outside of any functionmethod.


It depends on the intention of the use of these. For example, does
the type 'enum_txt' have a life outside the class? Is it shared by
another class, maybe? Then yes, it should be at the namespace level.
If it's specific to your class, limit its scope by putting the typedef
into the definition as well. If you do so, declare it 'public' only
if it's used outside the class hierarchy. Declare it 'protected' if
derived classes may need to use it. Otherwise declare it 'private'.

As to the declaration of an object of type 'enum_txt', you need to look
at how it's used. If you use 'phase_tab' only in that class' member
functions, why should it reside outside the class? No sense to pollute
the namespace with unnecessary names. You can probably get away by
making that object ('phase_tab') a static data member. Of course, if
it is used by some other functions in a context not related to your
class, put it at the namespace level as well.

IOW, the question of the scope for a name cannot be answered without
information on the use of the name.

V
Jul 22 '05 #2

P: n/a
It's no problem to put this statement "typedef const char *enum_txt[];"
in the definition of the class but how do I put
this statement "enum_txt phase_tab =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERR ELEASE","SPACE"};"
is the class definition because when I do I get compile error.

//Tony

"Victor Bazarov" <v.********@comAcast.net> skrev i meddelandet
news:7j*****************@newsread1.dllstx09.us.to. verio.net...
Tony Johansson wrote:
I have these two statements
typedef const char *enum_txt[];
and
enum_txt phase_tab
={"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTER RELEASE","SPACE"};

where in the class definition should these be put.

What I think is that this statement "typedef const char *enum_txt[];"
must be put in the header file outside of the class definition and this
statement "enum_txt phase_tab
={"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTER RELEASE","SPACE"};"
must be put in the implementation file outside of any functionmethod.


It depends on the intention of the use of these. For example, does
the type 'enum_txt' have a life outside the class? Is it shared by
another class, maybe? Then yes, it should be at the namespace level.
If it's specific to your class, limit its scope by putting the typedef
into the definition as well. If you do so, declare it 'public' only
if it's used outside the class hierarchy. Declare it 'protected' if
derived classes may need to use it. Otherwise declare it 'private'.

As to the declaration of an object of type 'enum_txt', you need to look
at how it's used. If you use 'phase_tab' only in that class' member
functions, why should it reside outside the class? No sense to pollute
the namespace with unnecessary names. You can probably get away by
making that object ('phase_tab') a static data member. Of course, if
it is used by some other functions in a context not related to your
class, put it at the namespace level as well.

IOW, the question of the scope for a name cannot be answered without
information on the use of the name.

V

Jul 22 '05 #3

P: n/a
Tony Johansson wrote:
It's no problem to put this statement "typedef const char *enum_txt[];"
in the definition of the class but how do I put
this statement "enum_txt phase_tab =
{"IDLE","LAUNCHING","LAUNCHED","ROLLING","BOOSTERR ELEASE","SPACE"};"
is the class definition because when I do I get compile error.


(a) Don't top-post.

(b) Don't put it in directly. Declare 'phase_tab' "static" and define
it (like any other static data member) at the namespace level. Read
your favourite C++ book about static data members. Pay attention
to the fact that 'enum_txt' is also a member if you declare it in the
class definition.

class HasTypeAndStatic { // class definition
typedef double *myDoublePtr; // type declaration
static myDoublePtr ptr; // data member declaration
};
...
HasTypeAndStatic::myDoublePtr HasTypeAndStatic::ptr = 0; // definition

V
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.