![]() |
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> |
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 { |
Hey!
Oh, Oh, Oh what a stupid mistake to make!!! Thanks for pointing out where I went wrong. At least, know I know where I went wrong :) Cheers :) |
| All times are GMT -5. The time now is 2:20 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC