C++ Programming - Objects and Classes - Discussion
Discussion Forum : Objects and Classes - General Questions (Q.No. 2)
2.
Which of the following statements is incorrect?
Discussion:
21 comments Page 2 of 3.
Neha Rani said:
1 decade ago
It is not the always the case, according to this link on stackoverflow:
It is required when a pointer of base class is cast to have derivedClas type, when we delete this pointer it is required to call derived class's destructor.
It is required when a pointer of base class is cast to have derivedClas type, when we delete this pointer it is required to call derived class's destructor.
Keerthana said:
1 decade ago
Friend function is only declared in the class. But why can't it be defined in main function, because we are only accessing the private data. So it can be access from anywhere in the program.
Sridharan said:
1 decade ago
Friend functions can be applied only to functions which can access private members of a class. A non member function of a class can access private members using friend function.
Thivakar R said:
1 decade ago
Friend function only initialize in-between main and class.
Ananya said:
1 decade ago
Friend keyword can be used on main() ? please explain I didn't get ?
Ranjeet Avghad said:
1 decade ago
Yes we can use friend keyword on main by defining main as member function of a class. So the data members of even though it is private can be accessible in main function. And program will execute properly.
Chaitanya said:
1 decade ago
Because main is entry point function.
Seema said:
1 decade ago
Please explain why friend keyword is not used with main()?
Prem said:
1 decade ago
Friend keyword is written inside one class(class a) to inform the same class(class a) that another class(class b) can access the private data of the other(class a).
eg: class a class b
{ {
private : int e; private : int f;
public : int x;
friend class b; }
}
In the above example, class b can access the private data of the class a.
eg: class a class b
{ {
private : int e; private : int f;
public : int x;
friend class b; }
}
In the above example, class b can access the private data of the class a.
Sweety said:
1 decade ago
friend keyword can be used on main() also i.e we can make main() as friend function.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers