繁体   English   中英

无法使用功能

[英]unable to access function

我为下面给出的二进制堆编写了一个程序-

       #include<iostream>
     using namespace std;
        /**
         * Construct the binary heap.
         * capacity is the capacity of the binary heap.
         */

class BinaryHeap
        {

           private:
            int   currentSize;  // Number of elements in heap
            int array[];        // The heap array

            void buildHeap( );
            void percolateDown( int hole );
           public:
            bool isEmpty( ) const;
            bool isFull( ) const;
            int findmini( ) const;

            void insert( int x );
            void deleteMin( );
            void deleteMin( int minItem );
            void makeEmpty( );



       public :
       BinaryHeap(  )
        {
         currentSize = 0;
        }
      BinaryHeap( int capacity )
        {
          array[capacity + 1];
         currentSize = 0;
        }
};
int main()
{
     int resp, ch, choice;
     int n, i;
     cout << "enter the size of heap" << endl;
     cin >> n;
    BinaryHeap b(int n);
   cout << "enter the item " << endl;
      cin >> ch;
    b.insert( int ch);


return 0;
}

在编译时会出现错误

请求“ b”中非类类型“ BinaryHeap(int)”的成员“插入”
和预期的'int'之前的主要表达式

为什么会发生这种情况以及如何解决?

BinaryHeap b(int n);移除int BinaryHeap b(int n); b.insert( int ch); 而且你很好。

调用函数时,不应指定调用它的变量的数据类型。

尝试改变这个

b.insert( int ch);

对此:

b.insert(ch);

暂无
暂无

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

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