473,468 Members | 1,358 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

enum doesn't seem to work correctly

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
2 1686

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
18
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
5
by: Andrea Williams | last post by:
I'm working with C# and I'm setting up some ENUM's I have a data and Business layer. I'm declaring a common enum for the Data Layer. The UI layer references the Bus layer and the bus layer...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
21
by: dllhell | last post by:
hi all, I have a problem with creating proc with a enum as a param. I wish to pass an enumeration in proc in which one I intend to do some operations with enumeration, but I don't know which one...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
3
by: Johnny Jörgensen | last post by:
Does anybody know how to correctly specify the defaultvalue attribute for a property whose type is an enum. Example: Public Enum TestValues Value1=1 Value2=2 End Enum
11
by: =?Utf-8?B?dG9iaXdhbl9rZW5vYmk=?= | last post by:
The following code is in a custom deserializer: object value = (int) 1; string nameToParse = Enum.GetName(field.FieldType, value); value = Enum.Parse(field.FieldType, nameToParse); Currently...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.