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 3 1395
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andrey Tatarinov |
last post by:
Hi.
It would be great to be able to reverse usage/definition parts in
haskell-way with "where" keyword. Since Python 3 would miss lambda, that
would be extremly useful for creating readable...
|
by: urocrane |
last post by:
i'm using visual c++ and it doesn't seem to have graphics header file.
where can i get it?
i've always had a wierd thought about prototypes, do you really need
them? in my case, i think it looks...
|
by: ganesh.gella |
last post by:
Hi All,
Wanted to make sure on this,
I have some functions for which I am providing the definition inside
the class definition. (As these are very small functions like get and
set).
Do i...
|
by: Ced |
last post by:
Hi,
i'm not an expert in C but i try to compile BTNG software under linux
kernel 2.4.2-2. I get these errors at the very first stage. Does
someone could have a rapid look on this and tell me...
|
by: marora |
last post by:
I have created class definition which contains
a charater pointer as one of it's data memeber.
The objective is to read some data from a file,
and assign it to a data member;
Size of data is...
|
by: Markus Kern |
last post by:
Hi!
I've been messing around with a template class. As usual, I do not
want to make the definition of my functions public, but only its
declaration. This was the concept of seperating...
|
by: garyusenet |
last post by:
I'm using an example piece of code: -
namespace Wintellect.Interop.Sound{
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
sealed class Sound{
public static...
|
by: joe t. |
last post by:
My apologies, i'm not sure how to ask this question correctly, so i'll
give the examples as i go.
First, i *think* my problem is described here, but i may be
misunderstanding:...
|
by: akomiakov |
last post by:
Is there a technical reason why one can't initialize a cost static non-
integral data member in a class?
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
| |