| | |
problem with returning pointer
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
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)
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
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
1
#2 Oct 22nd, 2009
•
•
•
•
C++ Syntax (Toggle Plain Text)
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....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
![]() |
Similar Threads
- Pointer to function returning a pointer to function (C++)
- Returning a pointer? (C++)
- Problem with Returning Pointer to local variable (C++)
Other Threads in the C++ Forum
- Previous Thread: if, while problem
- Next Thread: Templates with Operator Overloading Problem
Views: 240 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






