I was wondering if it is possible to create an array of enums like this:

typedef enum {
	LABEL,
	SCREEN_BUFFER,
	PID,
	ENABLED,
	NUM_BYTES
} SENSOR;

static SENSOR sensors[] = {
// formula // label //screen_buffer //pid //enabled // bytes
{ "Absolute Throttle Position:", "", "11", 1, 1 },
{ "Engine RPM:", "", "0C", 1, 2 },
{ "Vehicle Speed:", "", "0D", 1, 1 }
};

If this is not possible would someone give me some pointers on how to create something similar without have to build a class for each entry and storing it in a list or something like it. I'm trying to create a static array of a bunch of information about each sensor I can access on my vehicle through its OBD-II port.

Have you tried it? If so, did you receive any errors?

Member Avatar for jencas

Why enum? Use a struct!

I was wondering if it is possible to create an array of enums like this:

typedef enum {
	LABEL,
	SCREEN_BUFFER,
	PID,
	ENABLED,
	NUM_BYTES
} SENSOR;

static SENSOR sensors[] = {
// formula // label //screen_buffer //pid //enabled // bytes
{ "Absolute Throttle Position:", "", "11", 1, 1 },
{ "Engine RPM:", "", "0C", 1, 2 },
{ "Vehicle Speed:", "", "0D", 1, 1 }
};

As the previous poster said, you don't want to use an enum here.
You need something like:

struct
{
    char* LABEL;
    char* SCREEN_BUFFER;
    char* PID;
    int ENABLED;
    int NUM_BYTES;
} SENSOR;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.