C++ Union compilation errors

Discussion in 'C++' started by Sujal, Aug 14, 2008.

  1. Sujal

    Sujal Guest

    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();
    }
     
    Sujal, Aug 14, 2008
    #1
    1. Advertising

  2. Sujal

    Ian Collins Guest

    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.
     
    Ian Collins, Aug 14, 2008
    #2
    1. Advertising

  3. Sujal

    Sujal Guest

    On Aug 14, 1:51 pm, Ian Collins <> 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.
     
    Sujal, Aug 14, 2008
    #3
  4. Sujal

    Ian Collins Guest

    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.
     
    Ian Collins, Aug 14, 2008
    #4
  5. Sujal

    Sujal Guest

    On Aug 14, 2:33 pm, Ian Collins <> 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.
     
    Sujal, Aug 14, 2008
    #5
  6. Eberhard Schefold, Aug 14, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eqbal

    compilation errors

    Eqbal, Nov 18, 2003, in forum: VHDL
    Replies:
    0
    Views:
    1,180
    Eqbal
    Nov 18, 2003
  2. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    973
    Mark Goldin
    Jan 17, 2004
  3. Matt Garman
    Replies:
    1
    Views:
    672
    Matt Garman
    Apr 25, 2004
  4. Peter Dunker

    union in struct without union name

    Peter Dunker, Apr 26, 2004, in forum: C Programming
    Replies:
    2
    Views:
    879
    Chris Torek
    Apr 26, 2004
  5. C__chp
    Replies:
    4
    Views:
    512
    Puppet_Sock
    Feb 15, 2008
Loading...

Share This Page