Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

typedef error?

Status
Not open for further replies.

hongweiwu

Programmer
Nov 11, 2001
3
CN
The compiler says "your source code use a typedef symbol where a variable should appear in an expression" , "check for the declaration of the symbol and possible mispelling"
I know there's no mispelling. And I didn't use the key word "typedef" either, which is confusing me.
What's the other possible causes. Although there're some 6 errors, I believe they are caused by one same aspect of knowledge missing in my brain. Here I include my whole code here:


#include <math.h>
#include <fstream.h>
#include <iomanip.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>

//enum boolean {false, true};

const MaxTreeNo = 12;

class b_node
{
public:
b_node();
b_node(int, b_node * =NULL, b_node * =NULL);
int tell_key()
{ return the_key; };
const b_node * tell_l_child()
{ return l_child;};
const b_node * TellSibling()
{ return sibling;};
void print_all();
b_node & operator=( const b_node &);
void assign_l_child(b_node *);
void assign_sibling(b_node *);
void combine_nodes( b_node * another_node);//assuming this node is smaller
protected:
int the_key;
b_node * l_child;
b_node * sibling;
};

class b_heap
{
protected:
b_node tree[10];
void merge( b_heap &);
b_node & combine_trees(b_node &, b_node &);
};

void main()
{
clrscr();
b_node node1(1);
b_node node2(2);
b_node node3(3);
b_node node4(4);
node1.combine_nodes(&node2);
node3.combine_nodes(&node4);
node1.combine_nodes(&node3);
node1.print_all();
getch();
}

b_node::b_node()
{
the_key = NULL;
l_child=NULL;
sibling=NULL;
}

b_node::b_node( int Key,
b_node * LC, b_node * NS)
{
the_key=Key;
l_child=LC;
sibling=NS;
}

void b_node::print_all()
{
if(l_child!=NULL)
l_child->print_all();
if(sibling!=NULL)
sibling->print_all();
cout<<&quot; &quot;<<tell_key();
}

b_node & b_node::eek:perator=(const b_node & a_node)
{
the_key=a_node.the_key;
l_child=a_node.l_child;
sibling=a_node.sibling;
return * this;
}


void b_node::assign_l_child(b_node * some_node)
{
l_child=some_node;
}
void b_node::assign_sibling(b_node * some_node)
{
sibling=some_node;
}

void b_node::combine_nodes( b_node * another_node)
{
another_node->sibling = this->l_child;
this->l_child = another_node;
};

void b_heap::merge( b_heap & a_heap )
{
if( this == & a_heap )
{return;}
else
{
int i, WhichCase=0;
b_node Carry;
for(i=0; i<MaxTreeNo; i++)
{
b_node t1 = tree[ i ]; //root number i of this heap
b_node t2 = a_heap.tree[ i ];//root number i of the heap to Merge

WhichCase = (&t1 == NULL)? 0 : 1;
WhichCase +=(&t2 == NULL)? 0 : 2;
WhichCase +=(&Carry == NULL) ? 0 : 4;

switch( WhichCase )
{
case 0: break; // No trees
case 1: break; // Only this tree
case 2: // Only a_heap's tree
tree[ i ] = t2;
a_heap.tree[ i ] = NULL;
break;
case 4: // Only Carry
tree[ i ] = Carry;
Carry = NULL;
break;
case 3: /* this and a_heap */
Carry = combine_trees( t1, t2 );
tree[ i ] = a_heap.tree;
break;
case 5: /* this and Carry */
Carry = combine_trees( t1, Carry );
tree = NULL;
break;
case 6: /* rhs and Carry */
Carry = combine_trees( t2, Carry );
a_heap.tree[ i ] = NULL;
break;
case 7: /* All three */
tree[ i ] = Carry;
Carry = combine_trees( t1, t2 );
a_heap.tree[ i ] = NULL;
break;
}
}
}

b_node & b_heap::combine_trees(b_node & t1, b_node & t2 )
{
if(t1.tell_key()<=t2.tell_key())
{
t1.combine_nodes(t2);
return t1;
}
else
{
t2.combine_nodes(t1);
return t2;
}
}
 
Which symbol does it say that about?

Also, this probably isn't the cause of your error, but I see you're missing a } (closing brace) at the end of your merge function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top