"undefiend reference MaxHeap" [duplicate]

This question already has an answer here:

MaxHeap.h

private:
   int*heap;
   int heapSize;
   int capacity;

public:
   void changeSize1D(int*a,int oldSize,int newSize);
   MaxHeap::MaxHeap();

MaxHeap.cpp

MaxHeap::MaxHeap(){
   capacity=10;
   heap=new int[capacity+1];
   heapSize=0;
}


void changeSize1D(int*a,int oldSize,int newSize){

    int *temp=new int[newSize];

    int num=min(oldSize,newSize);
    copy(a,a+num,temp);
    delete []a;
    a=temp;
}

void MaxHeap::push(int i){
  if(heapSize==capacity){
    changeSize1D(heap,capacity,2*capacity);
    capacity*=2;
}

main.cpp

int main(void){
  MaxHeap mh;
  mh.push(7);
}

this code happen error

MaxHeap.cpp:(.text+0xfc): undefined reference to `MaxHeap::changeSize1D(int*, int, int)’

what’s the problem??


Source: c++

Leave a Reply