tags:

views:

973

answers:

1

I honestly have no idea why this is happening. I checked, double-checked, and triple-checked curly braces, semicolons, moved constructors around, etc. and it still gives me this error.

Relevant code follows.

BinTree.h

#ifndef _BINTREE_H
#define _BINTREE_H

class BinTree
{
private:
    struct Node
    {
        float data;
        Node *n[2];
    };
    Node *r;

    Node* make( float );

public:
    BinTree();
    BinTree( float );
    ~BinTree();

    void add( float );
    void remove( float );

    bool has( float );
    Node* find( float );
};

#endif

And BinTree.cpp

#include "BinTree.h"

BinTree::BinTree()
{
    r = make( -1 );
}

Node* BinTree::make( float d )
{
    Node* t = new Node;
    t->data = d;
    t->n[0] = NULL;
    t->n[1] = NULL;
    return t;
}
+10  A: 

Because on the line:

Node* BinTree::make( float d )

the type Node is a member of class BinTree.

Make it:

BinTree::Node* BinTree::make( float d )
Michael Burr
Geez, did NOT know you had to do that. Many thanks for clearing that up for me!
Freezerburn
It's tricky. Interestingly, you do NOT have to qualify *parameters* with `BinTree::` -- only return types.
j_random_hacker
@j_random_hacker: the parameter-declaration-clause (and everything that's part of a function definition after the identifier that names the function) is in the 'potential scope of a declaration' for a 'class definition' (3.3.6/5 "Class scope"). In other words, all members of a class are in scope for member function definitions *after* the name of the function. So the return type doesn't get the benefit of being in class scope; it comes too early. C++ 0x has a new *trailing-return-type* syntax that lets you work around this, but it's really being added for deducing return types in templates.
Michael Burr