#include <cstdlib>
#include <iostream>
usingnamespace std;
class Vehicle {
public:
int price = 1000;
int maxSpeed = 200;
};
class Toyota {
public:
int price = 500;
int maxSpeed = 3;
};
int main() {
Toyota a;
cout<<a.price;
}
However, when I run this code the following warning (during build) shows up:
warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
#include <cstdlib>
#include <iostream>
usingnamespace std;
class Vehicle
{
public:
Vehicle();
int price;
int maxSpeed;
};
Vehicle::Vehicle()
{
int price = 0;
int maxSpeed = 0;
}
class Toyota
{
public:
Toyota();
int price;
int maxSpeed;
};
Toyota::Toyota()
{
price = 0;
maxSpeed = 0;
}
int main()
{
Toyota a;
cout<<a.price;
}
Side note: your code would not compile in my compiler (Microsoft visual studio 2012 express) which is what i would expect.