Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Declaring member function of another class as friend before it isdefined

Thread Tools

Declaring member function of another class as friend before it isdefined

Cotangent Alpha
Posts: n/a
When class A is declared before class B is defined, I am unable to
make B::baz() a friend function of class A. I get this error: member
'void B::baz()' declared as friend before type 'B' defined. Is it
possible to resolve this?

Here is the code:

class B;

class A
void foo() {
cout << "A::foo()" << endl;

// This function should be accessible to B only and nothing else.
void bar() {
cout << "A::bar()" << endl;
friend void B::baz();

class B
void baz() {
A a;;

int main()
B b = b;
Reply With Quote

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring a template class with two template params a friend in anon-template class A L C++ 1 08-25-2010 07:25 AM
declaring a friend template function whose arguments are of type = private member type Hicham Mouline C++ 1 03-27-2009 03:58 PM
declaring class member functions as friend without full class definition Hicham Mouline C++ 0 11-11-2008 09:19 PM
Member function pointer to member function of another class Praetorian C++ 11 04-03-2008 08:33 PM
parse error in gcc but success in, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM