Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Midterm exam notes: Basic initializer list stuff:
- #include<iostream>
- using namespace std;
- class Point {
- private:
- int x;
- int y;
- public:
- Point(int i = 0, int j = 0):x(i), y(j) {}
- /* The above use of Initializer list is optional as the
- constructor can also be written as:
- Point(int i = 0, int j = 0) {
- x = i;
- y = j;
- }
- */
- int getX() const {return x;}
- int getY() const {return y;}
- };
- int main() {
- Point t1(10, 15);
- cout<<"x = "<<t1.getX()<<", ";
- cout<<"y = "<<t1.getY();
- return 0;
- }
- Basic operator overloading:
- std::ostream& operator<<(std::ostream& out, const Account& acct) {
- out << acct.toString();
- return out;
- >
- to_string is a thing!
- you can also do a function in a class like:
- string toString() {
- string result{};
- something something
- return result;
- }
- also think about getters and setters
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement