C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 2)
2.
Which of the following is not a type of constructor?
Copy constructor
Friend constructor
Default constructor
Parameterized constructor
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
68 comments Page 1 of 7.

Shashank said:   5 years ago
We have a friend class and function, not any constructor.

Constructors are of three types:
* Default Constructor.
* Parametrized Constructor.
* Copy Constructor.
(7)

Sid said:   5 years ago
A constructor can not be defined outside the class so Friend constructor can't be define.
(5)

Amarnath Rokade said:   6 years ago
Note: There are main 3 types only.

1. Default.
2. Parameterless.
3. Parameterized.

Copy constructor is under Parameterized constructor.
(2)

Ankita Kumari said:   6 years ago
It's not a constructor.

Constructors are basically of 3 types:
1. Default Constructor (without arguments).
2. Parameterized Constructor (with arguments).
3. Copy Constructor.

It is a function called Friend Function.

Friend Function is used to access private members of two different classes for which it has been declared as a friend.
(7)

Sharvari said:   7 years ago
The friend is not a type of any constructor. Right? If not please explain in detail.

Faisal Baloch said:   7 years ago
Because Constructor has three types:

1. Default Constructor.
2. Parameterized Constructor.
3. Copy Constructor.

Vidyashree bs said:   7 years ago
A friend is a function, but not a constructor.
(1)

Rambabu Yadav said:   8 years ago
class Y
{
public:
Y();
};
class X
{
private:
void foo() {}
friend Y::Y();
};
Y::Y()
{
X x; x.foo();
}

As per 11.3 Friends [class.friend]


When a friend declaration refers to an overloaded name or operator, only the function specified by the parameter types becomes a friend. A member function of a class X can be a friend of a class Y.

[ Example:

class Y {
friend char* X::foo(int);
friend X::X(char); // constructors can be friends
friend X::~X(); // destructors can be friends
};

"end example ]

Anita said:   8 years ago
Friend constructor is not a type of constructor.

Sneha Tiwari said:   8 years ago
Constructors, as we know have the same name as the class name. They can be three types of constructors namely:
1) Default constructor e.d constr() which has no parameters.
2) Parameterised constructors constr(x,y) that have some parameters passed to it.
3) Copy constructor constr(&object of constructor) that take input as the object of constructor type or rather copies the value of the constructor.

Friend functions exist but friend constructor don't exist in object oriented concept.
(1)


Post your comments here:

Your comments will be displayed after verification.