By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,028 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,028 IT Pros & Developers. It's quick & easy.

enum doesn't seem to work correctly

P: n/a
I have an enum defined within a namespace. When I reference the enum
using its qualified name graphics::db_status(VALUE) it does not work.

If I say "using namespace graphics;" then I can resolve the name of the
enumeration and its values.

The following code demonstrates the problem:
#include <db_RO.hpp>
/*
namespace graphics { enum db_status { FROM_FILE, FROM_DB, FROM_NOWHERE }; };
// actually defined in db_RO.hpp
*/
int main(int argc,char **argv) {
char ofile[255];
strcpy(ofile,"organ.cdbf");
if (argc>1) strcpy(ofile,argv[1]);

// scenario 1: DOES NOT WORK
graphics::db_RO thedb;
// next line generates "error: `FROM_DB' undeclared"
if (thedb.load(ofile)==graphics::db_status(FROM_DB))
thedb.save(ofile);

// scenario 2: DOES WORK
using namespace graphics;
db_RO thedb;
// however next line works in this case, why???
if (thedb.load(ofile)==db_status(FROM_DB))
thedb.save(ofile);

return 0;
};
Only scenario 2 works. In if() of the first scenario it makes no
difference if I say graphics::db_status(FROM_DB) or just
db_status(FROM_DB). Both generate the listed error condition.

Why???

I'm using gcc 3.3. Is this a compiler specific bug or am I using it
improperly?

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Wiseguy" <no***@all.com> wrote in message
news:pa****************************@all.com...
I have an enum defined within a namespace. When I reference the enum using its qualified name graphics::db_status(VALUE) it does not work.
If I say "using namespace graphics;" then I can resolve the name of the enumeration and its values.

The following code demonstrates the problem:

// next line generates "error: `FROM_DB' undeclared"
if (thedb.load(ofile)==graphics::db_status(FROM_DB))


Try:

if (thedb.load(ofile)==graphics::FROM_DB)

Jonathan

Jul 22 '05 #2

P: n/a
Wiseguy wrote:
I have an enum defined within a namespace. When I reference the enum
using its qualified name graphics::db_status(VALUE) it does not work.

If I say "using namespace graphics;" then I can resolve the name of the
enumeration and its values.

The following code demonstrates the problem:
#include <db_RO.hpp>
/*
namespace graphics { enum db_status { FROM_FILE, FROM_DB, FROM_NOWHERE }; };
// actually defined in db_RO.hpp
*/
int main(int argc,char **argv) {
char ofile[255];
strcpy(ofile,"organ.cdbf");
if (argc>1) strcpy(ofile,argv[1]);

// scenario 1: DOES NOT WORK
graphics::db_RO thedb;
// next line generates "error: `FROM_DB' undeclared"
if (thedb.load(ofile)==graphics::db_status(FROM_DB))
thedb.save(ofile);
Both 'db_status' and 'FROM_DB' are identifiers from namespace
'graphics'. You have to specify the scope resolution operator for both

if (thedb.load(ofile) == graphics::db_status(graphics::FROM_DB))
thedb.save(ofile);

However, I don't understand what is the purpose of the redundant
typecast in the above code. Why don't you just write

if (thedb.load(ofile) == graphics::FROM_DB)
thedb.save(ofile);

?
// scenario 2: DOES WORK
using namespace graphics;
db_RO thedb;
// however next line works in this case, why???
if (thedb.load(ofile)==db_status(FROM_DB))
thedb.save(ofile);


This should work, but then again why not just

if (thedb.load(ofile) == FROM_DB)
thedb.save(ofile);

?

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.