+ 3
What is super function and how it useful with c++?
3 Answers
+ 4
use for access base class parameters in derived class
+ 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?