繁体   English   中英

'*'标记之前的预期构造函数,析构函数或类型转换

[英]expected constructor, destructor, or type conversion before ‘*’ token

编译器说

error: expected constructor, destructor, or type conversion before ‘*’ token"

并指向.cpp中的这一行:

Node * Tree::buildTree(Node *myNode, int h) {

我猜可能是关于typedef事,但不是很确定。 可能是什么问题?

.h文件:

#ifndef TREE_H
#define TREE_H

class Tree {
    public:
    Tree();
    Tree(Tree const & other);
    ~Tree();
    Tree const & operator=(Tree const & other);

    private:
    class Node {
        public:
        Node() {
            data = 0;
        };
        Node(Node const & other) {
            _copy(other);
        };
        ~Node() {};
        Node const & operator=(Node const & other) {
            if (this != &other) 
                _copy(other);
            return *this;
        };

        Node *left;
        Node *right;
        int data;

        private:
        void _copy(Node const & other) {
            data = other.data;
            left = other.left;
            right = other.right;
        };
    };

    Node *root;

    Node * buildTree(Node *myNode, int h);
};

.cpp文件:

...

Node * Tree::buildTree(Node *myNode, int h) {
    if (h == 0)
        return NULL;
    myNode = new Node();
    myNode->left = buildTree(myNode->left, h - 1);
    myNode->right = buildTree(myNode->right, h - 1);
    return myNode;
}

...

NodeTree内部声明,因此您需要

Tree::Node * Tree::buildTree(Node *myNode, int h) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM