I am trying to learn C++ and I ran the following code in Visual Studio 2019. I am getting 12 errors , but the code runs fine on the website.
You can find the code here: https://www.tutorialspoint.com/cplusplus/cpp_static_members.htm
#include <iostream>
using namespace std;
class Box{
public:
static int objectCount;
//Constructor definition
Box(double l = 2.0 double b = 2.0 double h = 2.0) {
cout << "Constructor Called." << endl;
length = l;
breadth = b;
height = h;
//Increase everytime the object is created
objectCount++;
}
double Volume() {
return length * breadth* height;
}
private:
double length;
double breadth;
double height;
};
// Initialize static member of class Box
int Box::objectCount = 0;
int main(void) {
Box Box1(3.3, 1.2, 1.5);
Box Box2(8.5, 6.0, 2.0);
cout << "Total objects: " << Box::objectCount << endl;
return 0;
}