类引用另一个类.h文件的问题(希望很简单的修复)

时间:2019-04-03 23:36:50

标签: c++

我一直在Visual Studio中定义“类”。希望是一个简单的解决方法

代码:

main.ccp:

#include "pch.h"

#include <iostream>

#include <iomanip>

#include "TreeNode.h"

#include "AVLTree.h"

int main()

{

    AVLTree first;
        int y = 1;
        bool x = true;
        x = first.insert(1,2);
        std::cout << x << std::endl;
        std::cout << y << std::endl;

}

AVLTree.h:

#pragma once

class AVLTree

{

    int nodeCounter = 0;

    TreeNode * rootNode = 0; // It says the error is here (TreeNode undefined)

public:

    AVLTree();

    ~AVLTree();



    bool insert(int key, int value);

};

TreeNode.h:

#pragma once

class TreeNode

{
        int data;

    int key;

    TreeNode * nextPtr;
public:

    TreeNode();

    ~TreeNode();

};

1 个答案:

答案 0 :(得分:0)

尝试将以下内容添加到AVLTree.h:

class TreeNode;

以下是AVLTree.cpp:

#include "TreeNode.h"