hi, Im trying to have a function that would return a pointer and i cant seem to figure out what it is that the compiler complaining about.
I got the following error:
80 expected constructor, destructor, or type conversion before '*' token
80 expected `;' before '*' token
heres an excerpt from my program: (line 80 is in red)
#include <iostream>
#include <string>
#include <cstddef>
using namespace std;
template <typename Comparable>
class LeftistHeap
{
public:
LeftistHeap( );
LeftistHeap( const LeftistHeap & rhs );
~LeftistHeap( );
private:
struct LeftistNode
{
Comparable element;
LeftistNode *left;
LeftistNode *right;
int npl;
LeftistNode( const Comparable & theElement, LeftistNode *lt = NULL, LeftistNode *rt = NULL, int np = 0 )
: element( theElement ), left( lt ), right( rt ), npl( np ) { }
};
LeftistNode *root;
LeftistNode * merge( LeftistNode *h1, LeftistNode *h2 ) ; //Internal method to merge two roots.
LeftistNode * merge1( LeftistNode *h1, LeftistNode *h2 );
void copyTree(LeftistNode *treePtr, LeftistNode *&newTreePtr);
void destroyTree(LeftistNode *& t);
void insert( const Comparable & x );
};
template <typename Comparable>
LeftistHeap<Comparable>::LeftistHeap( const LeftistHeap & rhs )
{
copyTree(rhs.root, root);
}
template <typename Comparable>
LeftistHeap<Comparable>::~LeftistHeap()
{
destroyTree(root);
}
template <typename Comparable>
void LeftistHeap<Comparable>::insert( const Comparable & x )
{
LeftistNode *temp = new LeftistNode(x, NULL, NULL);
root = merge(root, temp);
}
template <typename Comparable>
LeftistNode* LeftistHeap<Comparable>::merge( LeftistNode *h1, LeftistNode *h2) //<----------------------problem code
{
if( h1 == NULL )
return h2;
if( h2 == NULL )
return h1;
if( h1->element < h2->element )
return merge1( h1, h2 );
else
return merge1( h2, h1 );
}
int main(){
LeftistHeap<string> heap2;
system("PAUSE");
return 0;
}
I have tried to do this...
template <typename Comparable>
LeftistHeap<Comparable>::LeftistNode* LeftistHeap<Comparable>::merge( LeftistNode *h1, LeftistNode *h2)
but that doesnt seem to help any
I have been pulling my hair out for this one but still cant figure out whats wrong. Hopefully i have included enough for people to help.
Thank You