+ 3

What is super function and how it useful with c++?

16th May 2018, 10:23 AM
Vijay Kumar Kanchukommala
Vijay Kumar Kanchukommala - avatar
3 Answers
+ 4
use for access base class parameters in derived class
16th May 2018, 10:25 AM
Mayur Chaudhari
Mayur Chaudhari - avatar
+ 4
#include <iostream> using namespace std; class Shape{ public: void parameter(int w, int l){ width=w; length=l; } protected : int width; int length; }; class Rectangle: public Shape{ public: int getArea(){ return width*length; } }; int main() { Rectangle rect; rect.parameter(5,7); cout<<rect.getArea(); return 0; } here in this program i am accessing "width" and "length" from base(shape) class to derived (Rectangle) class without super function. Then whats difference like this access and super() function access?
16th May 2018, 10:29 AM
Vijay Kumar Kanchukommala
Vijay Kumar Kanchukommala - avatar
16th May 2018, 10:31 AM
Vijay Kumar Kanchukommala
Vijay Kumar Kanchukommala - avatar