Skip to content

Instantly share code, notes, and snippets.

@asa55
Created April 3, 2020 20:48
Show Gist options
  • Save asa55/aa0a9319bbd002caba95d313db970f35 to your computer and use it in GitHub Desktop.
Save asa55/aa0a9319bbd002caba95d313db970f35 to your computer and use it in GitHub Desktop.
#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