34 lines
802 B
C++
34 lines
802 B
C++
#include <iostream>
|
|
|
|
/*
|
|
We copied the main function from the last example , but here we just have the Constructor outside of the class definition;
|
|
So the Constructor then gets defined like:
|
|
class::constructor
|
|
Like that you can make it more "readable";
|
|
*/
|
|
|
|
using namespace std;
|
|
|
|
class Car {
|
|
public:
|
|
string brand;
|
|
string model;
|
|
int year;
|
|
Car(string x , string y, int z);
|
|
};
|
|
|
|
Car::Car(string x, string y, int z) {
|
|
brand = x;
|
|
model = y;
|
|
year = z;
|
|
}
|
|
|
|
int main() {
|
|
Car volvo("Volvo", "VolvoAuto", 1989);
|
|
Car volkswagen("Volkswagen", "Golf", 2004);
|
|
|
|
cout << volvo.brand << " " << volvo.model << " " << volvo.year << "\n";
|
|
cout << volkswagen.brand << " " << volkswagen.model << " " << volkswagen.year << "\n";
|
|
|
|
return 0;
|
|
} |