Skip to content

Instantly share code, notes, and snippets.

@appkr
Created April 28, 2019 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appkr/b253d2a9fa4f93235f0bcc65f3646562 to your computer and use it in GitHub Desktop.
Save appkr/b253d2a9fa4f93235f0bcc65f3646562 to your computer and use it in GitHub Desktop.
Cpp

Dev Env

Programming

  • Note that a semicolon at the end of class definition
#include <iostream>
#include <string>

using namespace std;

class Foo {
private:
    string name;

public:
    Foo (string name) {
        this->name = name;
    }
    string getName() {
        return this->name;
    }
};

int main() {
    Foo foo = Foo("bar");
    cout << foo.getName();
}

Build and Run

$ gcc -o cpp cpp.cpp -lstdc++
$ ./cpp
# bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment