- #include (cmath) - cmath is library in which we can use maths function
- like - sqrt , cqrt , floor , ceil , round
- Pass the parameters from function if it returns something
- Function Prototype
- Program gets divided into two parts one is Header Information and Actual Implementation
- Parameters and Return Statement
- Remember the rules of PEMDAS when defining the body of your functions (P- Parentheses, E- Exponents, M- Multiplication, D- Division, A- Addition, and S- Subtraction)
- You can add default argument values to the function eg-double function(double pi = 3.14)
- If you are adding default arguements in a function then declare and define function before int main()
- It will not work if you define it after int main()
- Overloading Functions - Using same Name for various forms of that function
- Passing Arrays to C++ Function
- Pass by Reference
- Reference parameters (¶meter)
- Value doesnt changes even when parameter is passed into the function in main function
- Copy of constructor is used to intialize the members of newly created object by copying the members of an already existing object
- Copy of constructor has to be intialize in public:
- Shallow Copying with the Copy constructor
- Shallow Copy - Work With Heap Memory Allocation but if some variables are dynamically allocated memory from heap section then the copied object will also reference the same memory location
- Changes are made in copy constructor to define Shallow and Deep Constructor
- For Shallow(we use copy constructor as) - *data = source.data
- For Deep(we use copy constructor as) - *data = *source.data
- Deep - Copy Heap Storage (Not copying pointer we are copying data to the pointer)
- Shallow And Deep Copy Are One Of The Most Important Topic According To Me
- Move Constructors
- Can be used for efficiency
- Single & refers to L value and Double && refers to R value
- Move Constructor moves the resources in the heap
- Intialization in public: of Move Constructor : Move(Move &&source)noexcept;
- source.data = nullptr;: Important step or it will end up doing shallow copy
- The this Pointer
- Using const with Classes - std::string get_name() const{return name}
- Static Class Members
- Struct V/s Classes (Just Use Classes)
- Objects are by default public in Structs and private in Classes
- Friends of a Class - A Function or a Class that has access to the private class members (Will be used in next section in Operator Overloading)