The value of y will be 2.
Here’s how I got it to work in Visual Studio:
#include "stdafx.h"
#include <iostream>
class car
{
public:
static int x;
car();
};
int car::x = 0;
car::car(){
x = x + 1;
}
int main()
{
car first = car();// here the value of x is 1;
car tow = car();// here the value of x is 2;
int y = first.x; // here what the value of y
std::cout << y;
int wait;
std::cin >> wait;
}
0
solved what is the value of a static data member after a create more than one instance?