View Single Post
Old Nov 25th, 2004, 10:24 AM   #1
sys0p
Programmer
 
Join Date: Oct 2004
Posts: 73
Rep Power: 5 sys0p is on a distinguished road
Hi all!

I was working with classes, and was trying to test the friend directive. In the code below I keep getting the following error on compilation:

c:\c__~1\new\prac\struct~1\friend.cpp:35: no `int stack::compare(stack, stack)' member function declared in class `stack'

The code is below. I hope someone can help me out?

Cheers

#include <iostream.h>

const int SIZE = 100;

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 );
};

void stack::init( void )
{
count = 0;
};

void stack::push( const int item )
{
data[count] = item;
++count;
};

int stack::pop( void )
{
--count;
return(data[count]);
};

int stack::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);
};

main()
{
class stack myStack1;
class stack myStack2;

myStack1.push(4);
myStack2.push(3);

cout << compare( myStack1, myStack2 ) << '\n';

return(0);
};
sys0p is offline   Reply With Quote