Enumerated Array From MyStruct

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
            Shell.h
  #ifndef SHELL_H_INCLUDED
#define SHELL_H_INCLUDED
/****************************************
            Declare A Single Shell
 ****************************************/
struct Shell{
/***************************************
            status var :
       To Hold state of the ball
          (present=1, absent=0)
 ***************************************/
int status;
/*****************************************
        Constructor / Destructor
 ****************************************/
 Shell():status(0){};
 ~Shell(){};        //Should this be private to prevent deleting shells??
};
        /****************  EOF  ***************/

#endif // SHELL_H_INCLUDED
                             ShellGame.h


#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
/*********************************************************
            Declare Shell Status Enumeration
        ********************************************/
enum class Shell_Status{EMPTY,FULL};
/*********************************************************
            ShellGame Class
        ****************************/
class ShellGame{
    private:
/******************************************************** 
            Declare The Shell Array
        ************************************/
Shell shells[3];                     // Can This Be Turned into Enum Class
/********************************************************
       
};
                      *******   EOF   *********
 */




Can I use the Struct in my Game Class as an Enumeration Array maybe "ONE, TWO, THREE" instead of arr[0], arr[1], arr[2].
arrays and enums are completely different concepts. In arrays you can store value while enums are constants. So what are you trying to achieve?
I would say that anyone not trying to do something screwy by intent (hacking, being silly, demo-ing a bad idea, etc) would not be at risk of calling a destructor directly. I would leave it alone. If it does not do anything, take it out, the compiler will generate what you need.

what exactly do you want?
pure enums are really just grouped named constant integers. That is all they are, and that is all they can do.
you can enum/array combo cleanly:
enum {one,two,three,max_e};
object foo[max_e]; //if you add four to the enum before max_e, this self corrects on recompile!
foo[three] = value; //named locations are handy at times, eg cars[jaguar] = fast;

https://www.geeksforgeeks.org/enum-classes-in-c-and-their-advantage-over-enum-datatype/
From what I know of them (I have not found a use or need for one yet) enum class adds type safety which is as often an aggravation (possibly a legacy code issue, but often coders cram int to enum and reverse, ignoring the type. Old/bad habits? I know I usually want the integer from it, and find the C enum more useful.) as it is a boon. Otherwise, its just like an enum (assuming that you would put all enums in a namespace, which you would do, to prevent name collisions).

From what I see so far either namespaced enum or enum class will do it, yes.
if you want a text / int lookup, eg if the user typed 'three' and you wanted the enum value back, a map is the way to go usually.
Last edited on
Topic archived. No new replies allowed.