Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
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
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:55 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC