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


   LeftistHeap( );
   LeftistHeap( const LeftistHeap & rhs );
   ~LeftistHeap( );

        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>





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 );
      return merge1( h2, h1 );

int main(){

   LeftistHeap<string> heap2;

   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

7 Years
Discussion Span
Last Post by Free1ancer
Featured Replies
  • [QUOTE][CODE]template <typename Comparable> LeftistNode* LeftistHeap<Comparable>::merge( LeftistNode *h1, LeftistNode *h2) //<----------------------problem code[/CODE][/QUOTE] [CODE]template <typename Comparable> [COLOR="Red"]typename LeftistHeap<Comparable>::[/COLOR]LeftistNode* LeftistHeap<Comparable>::merge( LeftistNode *h1, LeftistNode *h2)[/CODE]? [url]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[/url] Read More

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)



Edited by Dave Sinkula: n/a


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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.