who called these functions?

Discussion in 'C++' started by holmescn, Apr 17, 2007.

  1. holmescn

    holmescn Guest

    I want to know who called these functions:
    the constructor
    the copy constructor

    the question from this code:

    class A
    {
    void func();
    };

    class B
    {
    friend class A:
    private:
    B();
    };

    void A::func()
    {
    B();
    }

    different compiler make different result.
    who can explain?

    Thx vary much.
     
    holmescn, Apr 17, 2007
    #1
    1. Advertising

  2. holmescn

    Salt_Peter Guest

    On Apr 17, 1:11 am, holmescn <> wrote:
    > I want to know who called these functions:
    > the constructor
    > the copy constructor
    >
    > the question from this code:
    >
    > class A
    > {
    > void func();


    This member function is private

    >
    > };
    >
    > class B
    > {
    > friend class A:


    The above colon is a syntax error

    > private:
    > B();


    This ctor is declared but not defined anywhere

    >
    > };
    >
    > void A::func()
    > {
    > B();
    >
    > }
    >
    > different compiler make different result.
    > who can explain?
    >
    > Thx vary much.


    Try something that compiles, then ask your question...

    #include <iostream>

    class A
    {
    public:
    void func();
    };

    class B
    {
    friend class A;
    private:
    B() { std::cout << "B()\n"; }
    };

    void A::func()
    {
    B b;
    }

    int main()
    {
    A a;
    a.func();
    }

    /*
    B()
    */
     
    Salt_Peter, Apr 17, 2007
    #2
    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. Apricot
    Replies:
    4
    Views:
    562
    velthuijsen
    Apr 16, 2004
  2. Xiangliang Meng
    Replies:
    1
    Views:
    1,663
    Victor Bazarov
    Jun 21, 2004
  3. Replies:
    0
    Views:
    5,678
  4. Weng Tianxiang
    Replies:
    6
    Views:
    606
    glen herrmannsfeldt
    Sep 12, 2007
  5. S_K
    Replies:
    6
    Views:
    1,255
    Robert Dunlop
    Nov 8, 2007
Loading...

Share This Page