- 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();
}
$ gcc -o cpp cpp.cpp -lstdc++
$ ./cpp
# bar