C ++:二进制堆

时间:2016-03-29 00:24:39

标签: c++

我正在开发二进制堆的C ++实现,但是我遇到了一些问题。这是我的代码片段:

class binaryHeap {

public:

    // Constructor
    binaryHeap(int _capacity)
    {
        // initializes the binary heap with a capacity, size, and space in memory
        _size = 0;
        _n = ceil(pow(2, log10(_capacity)/log10(2)));
        _heap = new int[_n];
    }

    ~binaryHeap(void)
    {
        delete[] _heap;
    }

/* Omitted: insert, remove, size, capacity functions
   Not necessary to the issue I'm having */

private:

    int _size;
    int _capacity;
    int _n;
    int *_heap;
};

在main.cpp文件中,当我写下以下行时:

struct BinaryHeap heap(10);

我收到错误:变量的类型'struct BinaryHeap'不完整。是什么原因引起了这个?

1 个答案:

答案 0 :(得分:2)

我认为这是一个拼写错误的问题。您的二进制堆类是binaryHeap,而在main函数中,您说的是struct BinaryHeap heap(10);,它在编译器的POV中是完全不同的类型。

相关问题