Expected constructor, destructor, or type conversi

2020-08-13 08:45发布

问题:

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;
}

回答1:

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 )


标签: c++