Skip to content

Instantly share code, notes, and snippets.

@poanchen
Created September 19, 2017 04:08
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 poanchen/d594efe13f0eac48396b2db052aeb808 to your computer and use it in GitHub Desktop.
Save poanchen/d594efe13f0eac48396b2db052aeb808 to your computer and use it in GitHub Desktop.
Write a simple class that uses with a private variable and a public member function.
// https://repl.it/LECL
#include <iostream>
using namespace std;
class SimpleClass
{
private:
string privateStr;
public:
void setPrivateStr(string text);
void printPrivateStr();
};
void SimpleClass::setPrivateStr(string text)
{
privateStr = text;
}
void SimpleClass::printPrivateStr()
{
cout << "privateStr is " + privateStr;
}
int main()
{
SimpleClass sc;
sc.setPrivateStr("yo\n");
sc.printPrivateStr();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment