View Single Post
Old Nov 25th, 2004, 12:06 PM   #2
Eggbert
Professional Programmer
 
Eggbert's Avatar
 
Join Date: Nov 2004
Posts: 250
Rep Power: 5 Eggbert is on a distinguished road
You have two problems:

>int stack::compare
compare is a friend, not a member. You don't qualify friends as if they were members unless they actually are.

>friend int compare( const stack &stack1, const stack &stack2 );
>int compare( const stack stack1, const stack stack2 )
Notice how the declaration takes references to a const stack and the definition takes const stack objects. These are two different functions and the compiler will treat them as overloads. Change the definition to match the declaration and the code will compile:
class stack {
private:
 int count;
 int data[SIZE];

public:
 void init( void );
 void push( const int item );
 int pop( void );
 friend int compare( const stack &stack1, const stack &stack2 );
};

...

int compare( const stack &stack1, const stack &stack2 )
{
 if( stack1.count != stack2.count )
  return(0);
 for( int i = 0; i < stack1.count; ++i )
 {
  if( stack1.data[i] != stack2.data[i] )
   return(0);
 };
 return(1);
};
Eggbert is offline   Reply With Quote