New Error For Me, Thanks for any help

This is a discussion on New Error For Me, Thanks for any help within the C++ Programming forums, part of the General Programming Boards category; Heyas, I am attempting to get my tree setup to receive the following constructors... Tree(void); Tree(Tree *, Tree *); Tree(unum,uchar); ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    2

    New Error For Me, Thanks for any help

    Heyas,
    I am attempting to get my tree setup to receive the following constructors...

    Tree(void);
    Tree(Tree *, Tree *);
    Tree(unum,uchar);

    When I compile I get these errors....


    tree.cpp: In function `int main()':
    tree.cpp:252: initializer list being treated as compound expression
    tree.cpp:252: invalid conversion from `uchar' to `Tree*'
    tree.cpp:253: initializer list being treated as compound expression
    tree.cpp:253: invalid conversion from `uchar' to `Tree*'
    tree.cpp:254: initializer list being treated as compound expression
    tree.cpp:254: warning: unused variable `Tree*r'


    This is the only initializer list I use....

    Node(unum d = 0, uchar l = '\0', Tree * ln = NULL, Tree *
    rn = NULL) :
    data(d),letter(l),left(ln),right(rn)
    {};

    This is the main function(test code) that I am working on.
    int main()
    {
    unum num = 5;
    uchar let = 's';
    Tree * s(num, let);
    Tree * t(num, let);
    Tree * r(s,t);
    //cout << r->getdata() << endl;
    return 0;
    }


    Any ideas are appreciated and an explanation of what the error actually is as I have not seen this one before and a better understanding of what the compiler is yelling about would be valuable in the long term.

    Tim Walter

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    59
    You have two options. Create a Tree on the stack or on the heap.

    On the stack: Tree tree(num, let);
    On the heap: Tree *tree = new Tree(num, let);

    You are trying to do a mix of it =)

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    2
    doh, thanks much.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21