who called these functions?

H

holmescn

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

Salt_Peter

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()
*/
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top