R
Randy
Compiling the following code
#include <iostream>
#include "cenum.h"
using namespace std;
class Test
{
CEnum MyCars("CAR", "Mustang, Nova, Pinto, Barracuda");
Test();
~Test();
};
int main(int argc, char **argv)
{
return 0;
}
I get
/home/yates/modetest/host/app/modetest/cenumbug.cpp:7: error: expected
identifier before string constant
/home/yates/modetest/host/app/modetest/cenumbug.cpp:7: error: expected
`,' or `...' before string constant
/home/yates/modetest/host/app/modetest/cenumbug.cpp:7: error: ISO C++
forbids declaration of `parameter' with no type
If, however, I pull the CEnum declaration out and put it in global
scope, it compiles fine.
What the heck is the problem here?
Here's cenum.h:
#ifndef _CENUM_H
#define _CENUM_H
/*******************************************************************************
Module: Enumeration Class Template (CEnum)
Author: Randy Yates
Creation Date: 10-Jan-2006
Description:
CEnum provides an enumeration class. Use CEnum as follows:
CEnum MyCars("CAR", "Mustang, Nova, Pinto, Barracuda");
The mechanism provides the following functionality:
1. Each enumeration identifier (e.g., "Mustang") and enumeration
typename (e.g., "CAR") is string-ized.
2. Each identifier is associated with a signed, 16-bit integer,
just as C's standard enumeration mechanism. For example, CEnum
can perform the equivalent of
typedef {First=-2, Second, Third=300, Fourth} MyEnumType;
where the initializers are optional.
3. CEnums overload the following operators:
MyCars++;
MyCars--;
MyCars = "Nova";
Iterators are incremented and decremented modulo ::Count().
4. Provides the following public member functions:
::Value() retrieves integer value of current
enumeration identifier.
::Value(uint16_t n) retrieves integer value of nth
enumeration identifier.
::String() retrieves string of current enumeration
identifier.
::String(uint16_t n) retrieves string of nth enumeration
identifier.
::Type() retrieves string of enumeration typename.
::Begin() retrieves beginning enumeration
identifier index (e.g., for use
in ::Value(n)). Indices are 0-based.
::Current() retrieves current enumeration identifier
index.
::End() retrieve ending enumeration identifier
index.
::Count() retrieves number of enumeration
identifiers.
::Set(uint16_t n) sets enumeration index to n.
::Set(string str) sets enumeration index to index
enumeration identifier string
corresponding to str. E.g.,
MyCars.Set("Mustang");
5. Provides inserters that will operate as in the following
example:
cout << MyCars;
yields
"CAR=Mustang"
6. Provides extractors that will operate as in the following
example:
cin >> MyCars;
when cin is "CAR=Mustang" will set the current enumeration
identier to "Mustang".
Note that this is equivalent to ::Set("Mustang").
7. When constructed, the default enumeration identifier index
will be set to 0.
Comment:
In order to "typedef" a specific enumeration type and use it in
multiple
instances (yes, this is kludgie, but I couldn't see a better way),
do this:
#define CAR_INSTANCE(a) CEnum a("CAR", "Mustange, Nova, Pinto,
Barracuda")
and then
CAR_INSTANCE MyCars;
*******************************************************************************/
#include <string>
#include <vector>
using namespace std;
#include <stdint.h>
class CEnum
{
uint16_t index;
uint16_t count;
vector<string> strEnumIDs;
vector<int> strEnumValues;
string strEnumType;
public :
enum {TOKEN_MAX_CHARS=256};
CEnum();
CEnum(string strEnumType, string strIdentifiers);
CEnum(string strEnumType, string strIdentifiers, string
strInitialIdentifier);
CEnum(string strEnumType, string strIdentifiers, uint16_t
nInitialIdentifier);
void Construct(string strEnumType, string strIdentifiers);
uint16_t Value();
uint16_t Value(uint16_t n);
string String();
string String(uint16_t n);
string Type();
uint16_t Begin();
uint16_t Current();
uint16_t End();
uint16_t Count();
bool Set(uint16_t n);
bool Set(string str);
string Dump();
CEnum operator++();
CEnum operator++(int notused);
CEnum operator--();
CEnum operator--(int notused);
virtual ~CEnum();
friend ostream& operator<<(ostream& os, CEnum& ce);
friend istream& operator>>(istream& is, CEnum& ce);
};
#endif
Please help!
--Randy
#include <iostream>
#include "cenum.h"
using namespace std;
class Test
{
CEnum MyCars("CAR", "Mustang, Nova, Pinto, Barracuda");
Test();
~Test();
};
int main(int argc, char **argv)
{
return 0;
}
I get
/home/yates/modetest/host/app/modetest/cenumbug.cpp:7: error: expected
identifier before string constant
/home/yates/modetest/host/app/modetest/cenumbug.cpp:7: error: expected
`,' or `...' before string constant
/home/yates/modetest/host/app/modetest/cenumbug.cpp:7: error: ISO C++
forbids declaration of `parameter' with no type
If, however, I pull the CEnum declaration out and put it in global
scope, it compiles fine.
What the heck is the problem here?
Here's cenum.h:
#ifndef _CENUM_H
#define _CENUM_H
/*******************************************************************************
Module: Enumeration Class Template (CEnum)
Author: Randy Yates
Creation Date: 10-Jan-2006
Description:
CEnum provides an enumeration class. Use CEnum as follows:
CEnum MyCars("CAR", "Mustang, Nova, Pinto, Barracuda");
The mechanism provides the following functionality:
1. Each enumeration identifier (e.g., "Mustang") and enumeration
typename (e.g., "CAR") is string-ized.
2. Each identifier is associated with a signed, 16-bit integer,
just as C's standard enumeration mechanism. For example, CEnum
can perform the equivalent of
typedef {First=-2, Second, Third=300, Fourth} MyEnumType;
where the initializers are optional.
3. CEnums overload the following operators:
MyCars++;
MyCars--;
MyCars = "Nova";
Iterators are incremented and decremented modulo ::Count().
4. Provides the following public member functions:
::Value() retrieves integer value of current
enumeration identifier.
::Value(uint16_t n) retrieves integer value of nth
enumeration identifier.
::String() retrieves string of current enumeration
identifier.
::String(uint16_t n) retrieves string of nth enumeration
identifier.
::Type() retrieves string of enumeration typename.
::Begin() retrieves beginning enumeration
identifier index (e.g., for use
in ::Value(n)). Indices are 0-based.
::Current() retrieves current enumeration identifier
index.
::End() retrieve ending enumeration identifier
index.
::Count() retrieves number of enumeration
identifiers.
::Set(uint16_t n) sets enumeration index to n.
::Set(string str) sets enumeration index to index
enumeration identifier string
corresponding to str. E.g.,
MyCars.Set("Mustang");
5. Provides inserters that will operate as in the following
example:
cout << MyCars;
yields
"CAR=Mustang"
6. Provides extractors that will operate as in the following
example:
cin >> MyCars;
when cin is "CAR=Mustang" will set the current enumeration
identier to "Mustang".
Note that this is equivalent to ::Set("Mustang").
7. When constructed, the default enumeration identifier index
will be set to 0.
Comment:
In order to "typedef" a specific enumeration type and use it in
multiple
instances (yes, this is kludgie, but I couldn't see a better way),
do this:
#define CAR_INSTANCE(a) CEnum a("CAR", "Mustange, Nova, Pinto,
Barracuda")
and then
CAR_INSTANCE MyCars;
*******************************************************************************/
#include <string>
#include <vector>
using namespace std;
#include <stdint.h>
class CEnum
{
uint16_t index;
uint16_t count;
vector<string> strEnumIDs;
vector<int> strEnumValues;
string strEnumType;
public :
enum {TOKEN_MAX_CHARS=256};
CEnum();
CEnum(string strEnumType, string strIdentifiers);
CEnum(string strEnumType, string strIdentifiers, string
strInitialIdentifier);
CEnum(string strEnumType, string strIdentifiers, uint16_t
nInitialIdentifier);
void Construct(string strEnumType, string strIdentifiers);
uint16_t Value();
uint16_t Value(uint16_t n);
string String();
string String(uint16_t n);
string Type();
uint16_t Begin();
uint16_t Current();
uint16_t End();
uint16_t Count();
bool Set(uint16_t n);
bool Set(string str);
string Dump();
CEnum operator++();
CEnum operator++(int notused);
CEnum operator--();
CEnum operator--(int notused);
virtual ~CEnum();
friend ostream& operator<<(ostream& os, CEnum& ce);
friend istream& operator>>(istream& is, CEnum& ce);
};
#endif
Please help!
--Randy