Advertisement
Felanpro

(Classes) Proper way to use variables

Nov 21st, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class FelixClass
  6. {
  7.       public:
  8.              void setName(string x)
  9.              {
  10.                   name = x;
  11.               }
  12.               string getName()
  13.               {
  14.                      return name;
  15.                      }
  16.              
  17.       private:
  18.              string name;      
  19. };
  20.  
  21. int main()
  22. {
  23.     FelixClass felixObject;
  24.     felixObject.setName("Felix is best!");
  25.     cout << felixObject.getName() << endl;
  26.     system("pause");
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement