473,379 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Enum |= and |

How do I allow my bitshifted enum to work with |= and |?

facebook::Gender::Gender facebook::Gender::fromXml(const QDomElement
&val)
{
if (val.nodeName() == "gender")
return facebook::Gender::fromString(val.text());
if (val.nodeName() == "meeting_sex")
{
Gender retval = facebook::Gender::unspecified;
QDomElement elt = val.firstChildElement();
while (!elt.isNull())
{
if (elt.nodeName() == "meeting_sex_elt")
retval |= fromString(elt.text()); //*********Error here (invalid
conversion from int to facebook::Gender::Gender)
elt.nextSiblingElement();
}
return retval;
}
return facebook::Gender::unspecified;
}

Oct 13 '06 #1
3 1401
th**********@gmail.com wrote:
How do I allow my bitshifted enum to work with |= and |?

facebook::Gender::Gender facebook::Gender::fromXml(const QDomElement
&val)
{
if (val.nodeName() == "gender")
return facebook::Gender::fromString(val.text());
if (val.nodeName() == "meeting_sex")
{
Gender retval = facebook::Gender::unspecified;
QDomElement elt = val.firstChildElement();
while (!elt.isNull())
{
if (elt.nodeName() == "meeting_sex_elt")
retval |= fromString(elt.text()); //*********Error here (invalid
conversion from int to facebook::Gender::Gender)
elt.nextSiblingElement();
}
return retval;
}
return facebook::Gender::unspecified;
}
Gender &operator |=(Gender &lhs, const Gender &rhs)
{
return lhs = lhs | rhs;
}

This should get you started.

John.
Oct 13 '06 #2

John Grabner wrote:
th**********@gmail.com wrote:
How do I allow my bitshifted enum to work with |= and |?

facebook::Gender::Gender facebook::Gender::fromXml(const QDomElement
&val)
{
if (val.nodeName() == "gender")
return facebook::Gender::fromString(val.text());
if (val.nodeName() == "meeting_sex")
{
Gender retval = facebook::Gender::unspecified;
QDomElement elt = val.firstChildElement();
while (!elt.isNull())
{
if (elt.nodeName() == "meeting_sex_elt")
retval |= fromString(elt.text()); //*********Error here (invalid
conversion from int to facebook::Gender::Gender)
elt.nextSiblingElement();
}
return retval;
}
return facebook::Gender::unspecified;
}
Gender &operator |=(Gender &lhs, const Gender &rhs)
{
return lhs = lhs | rhs;
}

This should get you started.

John.
That still errors on this line:
return lhs = lhs | rhs;

Oct 13 '06 #3
John Grabner wrote:
th**********@gmail.com wrote:
>How do I allow my bitshifted enum to work with |= and |?

facebook::Gender::Gender facebook::Gender::fromXml(const QDomElement
&val)
{
if (val.nodeName() == "gender")
return facebook::Gender::fromString(val.text());
if (val.nodeName() == "meeting_sex")
{
Gender retval = facebook::Gender::unspecified;
QDomElement elt = val.firstChildElement();
while (!elt.isNull())
{
if (elt.nodeName() == "meeting_sex_elt")
retval |= fromString(elt.text()); //*********Error here (invalid
conversion from int to facebook::Gender::Gender)
elt.nextSiblingElement();
}
return retval;
}
return facebook::Gender::unspecified;
}
Gender &operator |=(Gender &lhs, const Gender &rhs)
{
return lhs = lhs | rhs;
I think, that would not compile (and Comeau is with me): to compute

lhs | rhs

the enums get converted to their underlying integral type. The result has
not enum-type. You need to cast it back:

return ( lhs = Gender( lhs | rhs ) );

Of course, the cast also shows that one should think twice before doing
this.
}

Best

Kai-Uwe Bux
Oct 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
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
2
by: Dennis | last post by:
I have an enum as follows: Public Enum myData FirstData = 6 SecondData = 7 end enum Is there anyway that I can return the Enum names by their value, i.e., I want to input 6 into a function...
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)
10
by: Randy | last post by:
Hi, Can anyone point me to a complete, compilable example of Besser's ENUM++ mechanism? I downloaded it from CUJ and gave it a try but got errors just trying to compile the header enum.h. ...
1
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
2
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.