Created
April 3, 2020 20:48
-
-
Save asa55/aa0a9319bbd002caba95d313db970f35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#define print(s) std::cout << s << std::endl; | |
using String = std::string; // typedef std::string String; // I don't want to using namespace std - I only want to cherry-pick this one definition. | |
class Car { | |
public: | |
String brand; | |
String model; | |
int year; | |
Car(const char* brand, const char* model, int _year) { | |
(*this).brand = brand; // using this | |
this->model = model; // using this with arrow operator, same as pointer dereferencing above, looks cleaner | |
year = _year; // without this, could have been in an initialization list.... | |
}; | |
}; | |
int main() { | |
Car carObj1("hidy", "ho", 1776); | |
print(carObj1.year); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment