new a typedefed struct

Discussion in 'C++' started by Vincent SHAO, Apr 16, 2008.

  1. Vincent SHAO

    Vincent SHAO Guest

    There is a struct:

    struct _point{
    int x;
    int y;
    };
    typedef _point Point;

    struct _queue_node{
    Point coordinate;
    struct _queue_node* next;
    };
    typedef struct _queue_node Node;
    typedef struct _queue_node* pNode;

    Why i can't new a Node:
    pNode n=new Node(); //error:no appropriate default constructor
    available
    i can only pNode n=new _queue_node();
    Thank you
    Vincent SHAO, Apr 16, 2008
    #1
    1. Advertising

  2. Vincent SHAO

    Vincent SHAO Guest

    On 4ÔÂ16ÈÕ, ÉÏÎç9ʱ49·Ö, "Alf P. Steinbach" <> wrote:
    > * Vincent SHAO:
    >
    > > There is a struct:

    >
    > > struct _point{
    > > int x;
    > > int y;
    > > };
    > > typedef _point Point;

    >
    > In C++ just write
    >
    > struct Point { int x, y; };
    >
    > > struct _queue_node{
    > > Point coordinate;
    > > struct _queue_node* next;
    > > };
    > > typedef struct _queue_node Node;
    > > typedef struct _queue_node* pNode;

    >
    > In C++ just write
    >
    > struct Node
    > {
    > Point coordinate;
    > Node* next;
    > };
    >
    > > Why i can't new a Node:
    > > pNode n=new Node(); //error:no appropriate default constructor
    > > available

    >
    > Mysterious. Which compiler & version of that compiler are you using?
    > Academically it could be due to your use of names with leading underscores,
    > however, in practice I very much doubt that.
    >
    > Cheers, & hth.,
    >
    > - Alf


    Great thanks!
    Vincent SHAO, Apr 16, 2008
    #2
    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. RA Scheltema
    Replies:
    3
    Views:
    374
    RA Scheltema
    Jan 6, 2004
  2. Gunnar G

    struct in struct

    Gunnar G, May 31, 2004, in forum: C++
    Replies:
    14
    Views:
    777
  3. Chris Fogelklou
    Replies:
    36
    Views:
    1,335
    Chris Fogelklou
    Apr 20, 2004
  4. PSN

    typedefed enum

    PSN, May 4, 2006, in forum: C++
    Replies:
    1
    Views:
    330
    mlimber
    May 4, 2006
  5. Replies:
    2
    Views:
    406
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page