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 4 1714
"Randy" <ya***@ieee.org> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com... Compiling the following code
#include <iostream> #include "cenum.h" using namespace std;
class Test { CEnum MyCars("CAR", "Mustang, Nova, Pinto, Barracuda");
change to:
CEnum MyCars;
You're trying to create an object in a declaration. A class
definition only declares its members, it doesn't (can't)
create objects.
Test();
add:
Test(const CEnum& c) : myCars(c)
{
}
~Test(); };
int main(int argc, char **argv) {
Test(CEnum("CAR", "Mustang, Nova, Pinto, Barracuda"));
return 0; }
The reason it 'worked' with the CEnum declaration (which was
also a definition) at global scope is because it's OK to
create objects there. Inside a class definition, it's not.
There could be more wrong with your code, I didn't look any
further.
-Mike
Randy wrote: Compiling the following code
#include <iostream> #include "cenum.h" using namespace std;
class Test { CEnum MyCars("CAR", "Mustang, Nova, Pinto, Barracuda");
The above line is an error. You can't initialize MyCars in the Test
class declaration. If MyCars was meant to be a static member of the
class (in which case you omitted the "static" keyword), you must
initialize MyCars outside of the declaration. If MyCars is an ordinary
member, then you must initialize it in the constructor. You do
neither.
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.
Right, because you can initialize a variable at global (or namespace)
scope.
What the heck is the problem here?
Here's cenum.h: #ifndef _CENUM_H #define _CENUM_H
[long comments snipped]
#include <string> #include <vector> using namespace std;
The above line is generally a bad thing to include in a header file.
[remainder of header snipped.]
Best regards,
Tom
Randy wrote: Compiling the following code
#include <iostream> #include "cenum.h" using namespace std;
class Test { CEnum MyCars("CAR", "Mustang, Nova, Pinto, Barracuda");
This is a (badly formed) function declaration, not an object initialisation.
Ian
Ian <ia******@hotmail.com> writes: Randy wrote: Compiling the following code #include <iostream> #include "cenum.h" using namespace std; class Test { CEnum MyCars("CAR", "Mustang, Nova, Pinto, Barracuda");
This is a (badly formed) function declaration, not an object initialisation.
Ahh, thanks Ian. That explains the error message, which is what was
really throwing me off. Point taken on the namespace comment as well.
Thanks to everyone else as well. I appreciate the help.
--
% Randy Yates % "Ticket to the moon, flight leaves here today
%% Fuquay-Varina, NC % from Satellite 2"
%%% 919-577-9882 % 'Ticket To The Moon'
%%%% <ya***@ieee.org> % *Time*, Electric Light Orchestra http://home.earthlink.net/~yatescr This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lkrubner |
last post by:
I want to give users the power to edit files from an easy interface, so
I create a form and a PHP script called "fileUpdate". It does a
reasonable about of error checking and prints out some...
|
by: Reed L. O'Brien |
last post by:
I see rotor was removed for 2.4 and the docs say use an AES module
provided separately... Is there a standard module that works alike or
an AES module that works alike but with better encryption?...
|
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from...
|
by: MLH |
last post by:
I have some audio help files that play fine from within Access 97
and Access 2.0. Both are running on a Windows XP box. But I
do not know what program plays the files.
If I click Start, Run and...
|
by: Keith K |
last post by:
Having developed with VB since 1992, I am now VERY
interested in C#. I've written several applications with
C# and I do enjoy the language.
What C# Needs:
There are a few things that I do...
|
by: Niheel |
last post by:
Web 2.0 is this big buzz word that describes what is going on with internet technology today. It isn't this any one thing.
Like many of you, when I first heard it, I was confused. Immediately...
|
by: Alan Silver |
last post by:
Hello,
Just wondered what range of browsers, versions and OSs people are using
to test pages. Also, since I don't have access to a Mac, will I have
problems not being able to test on any Mac...
|
by: Xah Lee |
last post by:
in March, i posted a essay “What is Expressiveness in a Computer
Language”, archived at:
http://xahlee.org/perl-python/what_is_expresiveness.html
I was informed then that there is a academic...
|
by: markscala |
last post by:
I found the following ways to generate permutations on the ASPN:
Python Cookbook page.
SLOW (two defs):
def xcombinations(items,n):
if n == 0: yield
else:
for i in xrange(len(items)):
for...
|
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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:
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |