in CPP is there any concept of friend constructor

Is there any friend constructor concept in CPP. If yes then plz tell me about it.
No, it wouldn't make any sense.
There is Factory design pattern. Is that close, conceptually?
I don't know exactly what you mean...
Do you mean that only the constructor can be invoked by a friend from any of its methods;
or do you mean that only a certain function in a friend can invoke the constructor?

The first thing does NOT exist, a friend Method/class allways sees everything inside the class.
The second thing works partialy, but this method can see everything in the class (which makes sense)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class A
{
public:
    A();
};
class F
{
    F() {}
    int i; // also visible from A::A()
public:
    friend A::A();
};
A::A() {
  F f;
  f.i = 20;
}
Last edited on
I just want to know that , in cpp there is a concept of friend function, just as if there any concept of friend constructor or not.
Does the example shown in my last post satisfy your needs?
A constructor is a (special) function so you can declare a constructor as friend just like you can with normal functions. The same could be said about operators.
Topic archived. No new replies allowed.