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 7 of 7.
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 ]
Vidyashree bs said:
7 years ago
A friend is a function, but not a constructor.
(1)
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.
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.
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)
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.
1. Default.
2. Parameterless.
3. Parameterized.
Copy constructor is under Parameterized constructor.
(2)
Sid said:
5 years ago
A constructor can not be defined outside the class so Friend constructor can't be define.
(5)
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.
Constructors are of three types:
* Default Constructor.
* Parametrized Constructor.
* Copy Constructor.
(7)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers