I have my heap.h file that contains:
bool insert(int key, double data);
and in my heapCPP.cpp file I have:
bool heap::insert(int key, double data){
bool returnTemp;
node *temp = new node(key, data);
returnTemp = insert(temp);
delete temp;
return returnTemp;
}
However, I get a error saying "member function "heap::insert" may not be redeclared outside its class.
You possibly forgot a closing bracket in your cpp and this can be interpreted as redeclaring it inside another function.
The error message is clear enough. If function insert is a member function of class heap it shall be at first declared in the class definition.
For example
class heap
{
//...
bool insert(int key, double data);
//,,,
};
Take into account that you are using one more function with name insert inside the body of the first function
returnTemp = insert(temp);
So it seems you have some mess with function declarations and definitions.
I had the same error message, but in my case the problem was caused by a semi-colon in the .cpp file (from a bad copy and paste). That is, there was a semi-colon at the end of the function signature in the cpp file.
If I use your code as an example then,
heap.h:
bool insert(int key, double data);
heapCPP.cpp:
bool heap::insert(int key, double data);
{
// ...
}
Fix it with this in heapCPP.cpp:
bool heap::insert(int key, double data)
{
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With