This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef PERSON_H | |
| #define PERSON_H | |
| #include <iostream> | |
| #include <string> | |
| struct Person { | |
| /* | |
| Person operator=(const Person &person_p) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef PERSON_H /// header declaration --> if not define | |
| #define PERSON_H /// then define PERSON_H as a header | |
| #include <iostream> /// std::end; std::cout; | |
| #include <string> /// std::string; | |
| struct Person { | |
| Person operator=(const Person &person_p) { /// declares a function operator = to mimic a var = var assignment | |
| name = person_p.name; /// the left operand is the "this object" which is p2 and the right operand which we get in the argument is p1 | |
| address = person_p.address; /// assigning those values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> /// std::cout; std::endl; | |
| #include <string> /// std::string; | |
| struct race | |
| { | |
| void non_const_display() /// for non const just for to differentiate the two functions to understand | |
| { | |
| std::cout << "class: " << this->Class << std::endl | |
| << "job: " << this->job << std::endl | |
| << "level: " << this->level << std::endl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> /// std::cout; std::endl; | |
| #include <string> /// std::string; | |
| struct person | |
| { | |
| void display() | |
| { | |
| std::cout << "name = " << name << std::endl /// this was initialized and takes the address which this points which is p1 implicitly | |
| << "this->name = " << this->name << std::endl /// this points to an object which is p1 and dereference it and accessing those member which is name | |
| << "(*this).name = " << (*this).name << std::endl; /// this deference first what this points which is p1 and accessing those member which is name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> /// std::cout; std::endl; std::cerr; | |
| #include "Sales_data.h" /// Sales_data; o.isbn(); | |
| int main () | |
| { | |
| Sales_data total; | |
| if (std::cin >> total) { | |
| Sales_data trans; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| int display (int, int); | |
| int sum (int n1, int n2) | |
| { | |
| return n1 + n2; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> /// std::cout; std::endl; | |
| #include <vector> /// std::vector; | |
| int display (int, int); | |
| int sum (int n1, int n2) | |
| { | |
| return n1 + n2; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| /// function pointer | |
| int sum (int i, int ii) | |
| { | |
| return i + ii; | |
| } | |
| int (*ptr_f)(int, int) = sum; /// ptr_f is a function pointer that have a parameters of two int and returns int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| /// function pointers | |
| double sample_func (double d1, double d2) | |
| { | |
| std::cout << __func__ << " was called "; | |
| } | |
| int add (int n1, int n2) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> /// std::cout; std::endl; | |
| void useBigger (const std::string &s1, const std::string &s2, /// function useBigger has a parameters of two reference to const string and one pointer type that has paramters pf two const string and returns bool and returns void | |
| bool (*pf)(const std::string &, const std::string &)) | |
| { | |
| bool valid = pf (s1, s2); /// equivalent as lengthCompare (s1, s2); | |
| std::cout << __func__ << " is called " | |
| << valid <<std::endl; | |
| } |