Declaring member function of another class as friend before it isdefined

Discussion in 'C++' started by Cotangent Alpha, Jun 27, 2010.

  1. 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
    {
    public:
    void foo() {
    cout << "A::foo()" << endl;
    }

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


    class B
    {
    public:
    void baz() {
    A a;
    a.bar();
    }
    };

    int main()
    {
    B b = b;
    b.baz();
    }
     
    Cotangent Alpha, Jun 27, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob

    isdefined / isobject?

    Rob, Oct 18, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,151
    Bruce Barker
    Oct 18, 2005
  2. Replies:
    2
    Views:
    1,324
  3. Hicham Mouline
    Replies:
    0
    Views:
    338
    Hicham Mouline
    Nov 11, 2008
  4. Hicham Mouline
    Replies:
    1
    Views:
    356
    Vladyslav Lazarenko
    Mar 27, 2009
  5. A L
    Replies:
    1
    Views:
    511
    Alf P. Steinbach /Usenet
    Aug 25, 2010
Loading...

Share This Page