Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ Union compilation errors

Reply
Thread Tools

C++ Union compilation errors

 
 
Sujal
Guest
Posts: n/a
 
      08-14-2008
In below program, I'm getting below compilation errors

error C2621: member '_tag_nodes_::node_' of union '_tag_nodes_' has
copy constructor
error C2621: member '_tag_nodes_::linkednode_' of union '_tag_nodes_'
has copy constructor

Can anybody help me resolve this or any workaround for this?
I must need union because in my data structure only one type of node
is possible at time. So I have taken union. And ya my data structure
is still very big but i posted a fraction part here to simplify the
problem.

#include "stdafx.h"
#include <stdio.h>
#include<iostream>
#include<conio.h>
#include <list>
using namespace std;

typedef struct _tag_nodedata
{
std::string name;
std::string type;

}NODEDATAINFO;
typedef list<NODEDATAINFO> NODEDATA;
typedef struct _tag_nodeinfo
{
void *_nodeptr;
string path_;
NODEDATA data_;

}NODEINFO;
typedef struct _tag_linkednodeinfo
{
void *_nodeptr;
string linkpath_;
int queued;
int hidden;

}LINKEDNODEINFO;

typedef union _tag_nodes_
{
NODEINFO nodeinfo_;
LINKEDNODEINFO linkednode_;

}NODES;
typedef struct _unrsolvednode_
{
NODES node;
int type;
}UNRESOLVED;

int _tmain(int argc, _TCHAR* argv[])
{
getch();
}
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      08-14-2008
Sujal wrote:
> In below program, I'm getting below compilation errors
>
> error C2621: member '_tag_nodes_::node_' of union '_tag_nodes_' has
> copy constructor
> error C2621: member '_tag_nodes_::linkednode_' of union '_tag_nodes_'
> has copy constructor
>

It's telling you can can't put something with a constructor or
destructor in a union.

>
> typedef struct _tag_nodedata


You don't need the typedef in C++.
> {
> std::string name;
> std::string type;
>
> }NODEDATAINFO;


All caps for a class name is hideous!

>
> int _tmain(int argc, _TCHAR* argv[])


Why not write

int main(int argc, char* argv[])

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Sujal
Guest
Posts: n/a
 
      08-14-2008
On Aug 14, 1:51*pm, Ian Collins <(E-Mail Removed)> wrote:
> Sujal wrote:
> > In below program, I'm getting below compilation errors

>
> > error C2621: member '_tag_nodes_::node_' of union '_tag_nodes_' has
> > copy constructor
> > error C2621: member '_tag_nodes_::linkednode_' of union '_tag_nodes_'
> > has copy constructor

>
> It's telling you can can't put something with a constructor or
> destructor in a union.
>
>
>
> > typedef struct _tag_nodedata

>
> You don't need the typedef in C++.
>
> > {
> > std::string name;
> > std::string type;

>
> > }NODEDATAINFO;

>
> All caps for a class name is hideous!
>
>
>
> > int _tmain(int argc, _TCHAR* argv[])

>
> Why not write
>
> int main(int argc, char* argv[])
>
> --
> Ian Collins.


Hi Ian,
Thanks for even replying..
I have read on internet on Microsoft site that we can put structure in
Union.
Please refer below link....for more information.
http://msdn.microsoft.com/en-us/library/47azs69s.aspx

If I can't put structure type in union then i need to change my entire
data structure...
BTW, I have created temporary project so I haven't changed following
lines " int _tmain(int argc, _TCHAR* argv[])" while posting the
message.

thanks.

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      08-14-2008
Sujal wrote:

[please don't quote signatures]
>
> Hi Ian,
> Thanks for even replying..
> I have read on internet on Microsoft site that we can put structure in
> Union.


You can, but the structure may not have a non-trivial constructor, copy
constructor or destructor. See 9.5.1 in the standard.

One of your structures contained std::strings, so they can't be a member
of a union.

--
Ian Collins.
 
Reply With Quote
 
Sujal
Guest
Posts: n/a
 
      08-14-2008
On Aug 14, 2:33*pm, Ian Collins <(E-Mail Removed)> wrote:
> Sujal wrote:
>
> [please don't quote signatures]
>
>
>
> > Hi Ian,
> > Thanks for even replying..
> > I have read on internet on Microsoft site that we can put structure in
> > Union.

>
> You can, but the structure may not have a non-trivial constructor, copy
> constructor or destructor. *See 9.5.1 in the standard.
>
> One of your structures contained std::strings, so they can't be a member
> of a union.
>
> --
> Ian Collins.


Hi Ian,
Oh now I got your point. std::strings.... Thanks for that.
Can you please tell me where can I find 9.5.1 Standard. Can you please
share link for that?
Thanks in advance.
 
Reply With Quote
 
Eberhard Schefold
Guest
Posts: n/a
 
      08-14-2008
Sujal wrote:

> Can you please tell me where can I find 9.5.1 Standard. Can you please
> share link for that?


http://www.parashift.com/c++-faq-lit....html#faq-6.13
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation error with seperate compilation C__chp C++ 4 02-15-2008 03:57 PM
union in struct without union name Peter Dunker C Programming 2 04-26-2004 07:23 PM
map XML union to C union (and vice-versa) Matt Garman XML 1 04-25-2004 12:40 AM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM
compilation errors Eqbal VHDL 0 11-18-2003 08:07 PM



Advertisments