Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
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; };_C++ - Fatal编程技术网

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

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; };,c++,C++,在main.cpp文件中,当我写入以下行时: struct BinaryHeap heap(10); 我发现错误:变量的类型“struct BinaryHeap”不完整。你知道这是什么原因吗?我认为这是个打字错误。您的二进制堆类是binaryHeap,而在主函数中,您说的是struct binaryHeap heap10;,在编译器的POV中是完全不同的类型。如果你正在做C++,你可能想使用STD::vector代替C风格数组。它也是二进制堆还是二进制堆?后者是更传统的C++,为什么使用Str

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

struct BinaryHeap heap(10);

我发现错误:变量的类型“struct BinaryHeap”不完整。你知道这是什么原因吗?

我认为这是个打字错误。您的二进制堆类是binaryHeap,而在主函数中,您说的是struct binaryHeap heap10;,在编译器的POV中是完全不同的类型。

如果你正在做C++,你可能想使用STD::vector代替C风格数组。它也是二进制堆还是二进制堆?后者是更传统的C++,为什么使用Strut BialHeAPAP HEAP10;为什么不直接使用二进制堆heap10;?第二,有个打字错误。哇,就这么简单,哈哈。谢谢