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?
Discussion:
68 comments Page 4 of 7.
Anita said:
8 years ago
Friend constructor is not a type of constructor.
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 ]
{
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 ]
Faisal Baloch said:
7 years ago
Because Constructor has three types:
1. Default Constructor.
2. Parameterized Constructor.
3. Copy Constructor.
1. Default Constructor.
2. Parameterized Constructor.
3. Copy Constructor.
Sharvari said:
7 years ago
The friend is not a type of any constructor. Right? If not please explain in detail.
Nagesh said:
1 decade ago
Parameterized constructor is just like default constructor but allows the parameters just like functions with parameters.
Sushil Sinha said:
1 decade ago
Friend is not a constructor. It is just a function. All options except friend are types of constructor.
Sahithi said:
1 decade ago
Friend is a function but it is not a constructor.
Pradeep said:
1 decade ago
Friend Keyword is used for class and Functions. Rest of the 3 options are available constructor in c++.
Manu said:
1 decade ago
Because friend function is used not constructor.
Sujit kumar said:
1 decade ago
Friend is not a constructor its a function.
Remaining all option to be under the constructor type.
Constructor is used to invoke the object.
Remaining all option to be under the constructor type.
Constructor is used to invoke the object.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers