problem with returning pointer

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 2
Reputation: Free1ancer is an unknown quantity at this point 
Solved Threads: 0
Free1ancer Free1ancer is offline Offline
Newbie Poster

problem with returning pointer

 
0
  #1
Oct 22nd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c
 
1
  #2
Oct 22nd, 2009
  1. template <typename Comparable>
  2. 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....nversion&pli=1
Last edited by Dave Sinkula; Oct 22nd, 2009 at 6:45 pm.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: Free1ancer is an unknown quantity at this point 
Solved Threads: 0
Free1ancer Free1ancer is offline Offline
Newbie Poster
 
0
  #3
Oct 22nd, 2009
thanks alot Dave... that solves everything
now i dont have to search aimlessly for a solution online anymore
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 240 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC