31 lines
701 B
C++
31 lines
701 B
C++
#include <iostream>
|
|
|
|
/*
|
|
Here we have a more "practical" approach to Constructors ;
|
|
We use the constructor here to print out some predefined data from a Class Object
|
|
*/
|
|
|
|
using namespace std;
|
|
|
|
class Car {
|
|
public:
|
|
string brand;
|
|
string model;
|
|
int year;
|
|
|
|
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;
|
|
} |