Advertisement
193030

01. OOP Basics

Sep 6th, 2023
1,025
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class Person {
  5.  public:
  6.   std::string first;
  7.   std::string last;
  8.  
  9.   void printFullName() { std::cout << first << " " << last << std::endl; }
  10. };
  11.  
  12. int main() {
  13.   Person p;
  14.   p.first = "Caleb";
  15.   p.last = "Curry";
  16.   std::string first = "Caleb";
  17.   std::string last = "Curry";
  18.  
  19.   p.printFullName();
  20.   return 0;
  21.  
  22.   // class - describes the structure
  23.   // object - an instance of the structure
  24.   // instance - other name of an object
  25.   // instantiaining
  26.   // data members - variables
  27.   // methods - functions
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement