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. Advertisements

  2. holmescn

    Salt_Peter Guest

    This member function is private
    The above colon is a syntax error
    This ctor is declared but not defined anywhere
    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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.