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.

Shudhanshu shekhar said:   1 decade ago
There are three types of constructors:

1. Default constructor -->no parameter.

2. Parameterised constructor-->having parameters like arguments of a function.object is declared with blues for that arguments.

3. Copy constructor-->invoked when an object is copied to another object.

classname ob1;
ob2=ob1; /*copy constructor called*/

When an object is passed by value to a function then also copy constructor is invoked.

Note--> Array of objects can never be created without default constructor. If two default constructors are there i mean first having no argument and second having default argument then error will generated while creating array of objects.

So it is desirable to declare only one default constructor while creating array of objects.

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 ]

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)

Chetna Borse said:   9 years ago
Constructor is used to initialize the objects and the name of the constructor is same as the name of the class. And we can say construct the values of data members.

for eg. class demo
{
int a;
demo()
{
a=0
}
};

In this example, demo is the class and the name with parentheses is the constructor.
Whenever we create the object of the class demo the constructor will be called and assign value 0 to variable a.

Pooja Naokar said:   1 decade ago
There are 3 types of constructors

1. Default constructor with no parameters.
2. Parameterized constructor as its name implies with
one or more parameters.
3. Copy constructor which takes reference of object as
parameter.

And Friend is a funcion to access private members of 2 different classes to which it has been declaredas friend.

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)

Sumesh sg said:   1 decade ago
Because friend is a non member function.

It is a function and not a constructor.

Since there are 3 types of constructor i.e.

1. Parameterized constructor.
2. Default constructor.
3. Copy constructor.

Suresh said:   1 decade ago
Constructor are used to initialize the object. The Friend constructor is not available as a constructor. Friend is function. which use to access the data and methods of the defined class.

Varun Vivek J said:   1 decade ago
Friend is a function.

Where as all others are constructors.

Its a pre defined function and can be used to create functions whereas, constructors are used for functions itself!

Rajput yogesh said:   1 decade ago
1. Constructor.

2. Copy constructor.

3. Default constructor.

4. Parameterized constructor, only three type of constructor also friend is a special member function are there.


Post your comments here:

Your comments will be displayed after verification.