Declare Static members as public and Show the behavior change of those members by writing relative member functions.Declare Static members as public and Show the behavior change of those members by writing relative member functions.
#include <iostream>
using namespace std;
class A {
private:
double x1;
double y1;
double z1;
public:
static int count;
A(double x, double y, double z) {
x1=x;
y1=y;
z1=z;
count++;
}
double Volume() {
return x1*y1*z1;
}
};
int A::count = 0;
int main(void) {
A a1(1.1, 2.2, 3.3);
A a2(4.4, 5.5, 6.6);
cout << "Number of objects created= " << A::count << endl;
return 0;
}
Comments
Leave a comment