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

Recommended Answers

All 2 Replies

template <typename Comparable>
LeftistNode* LeftistHeap<Comparable>::merge( LeftistNode *h1, LeftistNode *h2)  //<----------------------problem code
template <typename Comparable>
typename LeftistHeap<Comparable>::LeftistNode*
LeftistHeap<Comparable>::merge( LeftistNode *h1, LeftistNode *h2)

?

http://groups.google.com/group/comp.lang.c++/browse_thread/thread/830178e40acca27a/2825ed52b5ae3fac?ie=UTF-8&q=group%3Acomp.lang.c%2B%2B+expected+constructor+destructor+or+type+conversion&pli=1

thanks alot Dave... that solves everything
now i dont have to search aimlessly for a solution online anymore :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.