[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Problem while using anonymous union in C++

SRK

10/21/2008 9:41:00 AM

Hi,
I wanted to use an anonymous union within an structure something like
below -

struct Test
{
union
{
std::string user; //char user[50];
std::string role; //char role[50];
};
std::string desc;
};

Whenever I use, built in data types such as int, char etc, it works
perfectly fine, but for user defined dataypes, it gives me error -

error: member `std::string Test::<anonymous union>::user' with
constructor not allowed in union
error: member `std::string Test::<anonymous union>::user' with
destructor not allowed in union
error: member `std::string Test::<anonymous union>::user' with copy
assignment operator not allowed in union
error: member `std::string Test::<anonymous union>::role' with
constructor not allowed in union
error: member `std::string Test::<anonymous union>::role' with
destructor not allowed in union
error: member `std::string Test::<anonymous union>::role' with copy
assignment operator not allowed in union

Can someone give any idea, how to sort out the problem?

Thanks in advance.

- Shiv Ranjan
kumarsr@gmail.com
5 Answers

anon

10/21/2008 10:06:00 AM

0

SRK wrote:
> Hi,
> I wanted to use an anonymous union within an structure something like
> below -
>
> struct Test
> {
> union
> {
> std::string user; //char user[50];
> std::string role; //char role[50];
> };
> std::string desc;
> };

This is not allowed (using std::string in a union)

>
> Whenever I use, built in data types such as int, char etc, it works
> perfectly fine, but for user defined dataypes, it gives me error -
>
> error: member `std::string Test::<anonymous union>::user' with
> constructor not allowed in union
> error: member `std::string Test::<anonymous union>::user' with
> destructor not allowed in union
> error: member `std::string Test::<anonymous union>::user' with copy
> assignment operator not allowed in union
> error: member `std::string Test::<anonymous union>::role' with
> constructor not allowed in union
> error: member `std::string Test::<anonymous union>::role' with
> destructor not allowed in union
> error: member `std::string Test::<anonymous union>::role' with copy
> assignment operator not allowed in union
>
> Can someone give any idea, how to sort out the problem?
>

Listen what your compiler is telling you

SRK

10/22/2008 7:56:00 AM

0

On Oct 21, 3:06 pm, anon <a...@no.invalid> wrote:
> SRK wrote:
> > Hi,
> > I wanted to use an anonymous union within an structure something like
> > below -
>
> > struct Test
> > {
> >     union
> >     {
> >         std::string user; //char user[50];
> >         std::string role;  //char role[50];
> >     };
> >     std::string desc;
> > };
>
> This is not allowed (using std::string in a union)
>
>
>
>
>
> > Whenever I use, built in data types such as int, char etc, it works
> > perfectly fine, but for user defined dataypes, it gives me error -
>
> > error: member `std::string Test::<anonymous union>::user' with
> > constructor not allowed in union
> > error: member `std::string Test::<anonymous union>::user' with
> > destructor not allowed in union
> > error: member `std::string Test::<anonymous union>::user' with copy
> > assignment operator not allowed in union
> > error: member `std::string Test::<anonymous union>::role' with
> > constructor not allowed in union
> > error: member `std::string Test::<anonymous union>::role' with
> > destructor not allowed in union
> > error: member `std::string Test::<anonymous union>::role' with copy
> > assignment operator not allowed in union
>
> > Can someone give any idea, how to sort out the problem?
>
> Listen what your compiler is telling you

I understand what the compiler is saying and thats why I wanted
whether there is any workaround for that or not?

- Shiv

dertopper

10/22/2008 8:41:00 AM

0

> > SRK wrote:
> > > Hi,
> > > I wanted to use an anonymous union within an structure something like
> > > below -
>
> > > struct Test
> > > {
> > >     union
> > >     {
> > >         std::string user; //char user[50];
> > >         std::string role;  //char role[50];
> > >     };
> > >     std::string desc;
> > > };
>
> > This is not allowed (using std::string in a union)
>
> > > Whenever I use, built in data types such as int, char etc, it works
> > > perfectly fine, but for user defined dataypes, it gives me error -
>
[snipped error messages]
>
> > > Can someone give any idea, how to sort out the problem?
>
> > Listen what your compiler is telling you
>
> I understand what the compiler is saying and thats why I wanted
> whether there is any workaround for that or not?

There's no workaround for this. Why don't you use the following:

class Test
{
private:
std::string user_or_role;
public:
std::string& get_user ()
{
return user_or_role;
}

std::string& get_role ()
{
return user_or_role;
}
std::string desc;
};

Regards,
Stuart

RBRK

10/22/2008 9:46:00 AM

0

Re: Islam responsible for rampant child abuse across .... Chief William
Matthews, child, Child Abuse Taskforce, child bride -
http://www.downundernewslinks.com/2008/01/28/indonesia-islam-to-blame-for-child-abuse-says-protect...



HOW TO BECOME A SHITSKIN MOSLEM - this is how: fuck goats, fuck your
mother (nikomak), molest children, wear a beekeepers outfit all the
time, never shower or bath, beat your wives, learn terrorist activities
at a maddrassa, wipe your ass with stones, sell the donkey you fucked to
a nearby village, marry a nine year-old , send your child off to an
indoctrination camp, practice thighing with little kids, ............
Practice all those and you too could become a prophet !!


Elif air ab tizak mohammad !!!!

info@muslimmatch.com or apache@muslimmatch.com or
Achmat.Samsodien@gmail.com
ipcisa@yebo.co.za
politicsIranian@googlegroups.com
jamiat@islamsa.org.za
dsirc@mweb.co.za
arah1958@gmail.com
jamiatmp@lantic.co.za
sanha-kzn@sanha.org.za
sanha-gp@sanha.org.za
sanha-cpt@sanha.org.za
helpline@sanha.org.za
islamwayoflife@googlegroups.com
furtivo4000@gmail.com

** Posted from http://www.te... **

Moslem cartoon character mohammed was a paedophile 6th century warlord who cooked up a false religio

10/22/2008 10:50:00 AM

0

RBRK wrote:
> Saudis indict 991 Muslim terrorism suspects - Saudi authorities have
> indicted 991 Islamic militants for participating in terrorist attacks
> carried out over the past five years, the interior minister said
> yesterday.Saudi authorities have indicted 991 suspected militants for
> participating in terrorist attacks carried out over the past five years,
> the interior minister said yesterday. -
> http://www.guardian.co.uk/world/2008/oct/22/saudi-arabia-terrorism-tria...
>
>
>
> ** Posted from http://www.te... **
>
>
> moslem cartoon character mohammad and his bumchum allaah were child
> molesting goat fuckers and nikomaks
>
>
> _
> /'_/)
> ,/_ /
> / /
> /'_'/' '/'__'7,
> /'/ / / /" /_> ('( ' /' ')
> \ /
> '\' _.7'
> \ (
> \ >
> Up your ass mohammad - Elif air ab tizak!!!
>
> info@muslimmatch.com or apache@muslimmatch.com or
> politicsIranian@googlegroups.com
> Achmat.Samsodien@gmail.com
> jamiat@islamsa.org.za
> dsirc@mweb.co.za
> jamiatmp@lantic.co.za
> sanha-kzn@sanha.org.za
> sanha-gp@sanha.org.za
> sanha-cpt@sanha.org.za
> helpline@sanha.org.za
> arah1958@gmail.com
> islamwayoflife@googlegroups.com
> furtivo4000@gmail.com
> ipcisa@yebo.co.za
>
> ** Posted from http://www.te... **
moslem cartoon character mohammad and his bumchum allaah were child
molesting goat fuckers and nikomaks


_
/'_/)
,/_ /
/ /
/'_'/' '/'__'7,
/'/ / / /" /_ ('( ' /' ')
\ /
'\' _.7'
\ (
\
Up your ass mohammad - Elif air ab tizak!!!

info@muslimmatch.com or apache@muslimmatch.com or
politicsIranian@googlegroups.com
Achmat.Samsodien@gmail.com
jamiat@islamsa.org.za
dsirc@mweb.co.za
jamiatmp@lantic.co.za
sanha-kzn@sanha.org.za
sanha-gp@sanha.org.za
sanha-cpt@sanha.org.za
helpline@sanha.org.za
arah1958@gmail.com
islamwayoflife@googlegroups.com
furtivo4000@gmail.com
ipcisa@yebo.co.za

** Posted from http://www.te... **


Vera "Mirelle" Perks
609 Turner St
Silverton, BC
V0G2B0
Phone 250-358-2727

labellemirelle@gmail.com

http://moaningmirelle.blo...

ISP - Telus Communications

arah1958@gmail.com
Achmat.Samsodien@gmail.com
jamiat@islamsa.org.za
dsirc@mweb.co.za
jamiatmp@lantic.co.za
sanha-kzn@sanha.org.za
sanha-gp@sanha.org.za
sanha-cpt@sanha.org.za
helpline@sanha.org.za
islamwayoflife@googlegroups.com
furtivo4000@gmail.com

** Posted from http://www.te... **