1/23
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
g++
.hpp
.cpp
.tpp
function overloading
reusing function names w/o overwriting
AS LONG AS FUNCTION SIGNIATURE CHANGES
func name
param types
param orders
PARAM NAMES DONT MATTER!
static cast
static_cast<new_type>(expression)
simple conversiom
dynamic cast
dyamic_cast<new_type>(expression)
converting base class —> derived class
constant cast
const_cast<new_type>(expression)
data type <—> constant
basically cheating, goes against the purpose of const
reinterpret cast
reinterpret_cast<new_type>(expression)
whats in memory addr —> new type
const
variable whose value never changes
prevents modifying BOTH ADDRESS AND VALUES stored in const pointers
const int datatype = value;
pass by reference
multi dimension arrays/double pointers
c style casting
classes: basic syntax
class ClassName {
public:
private:
protected:
};
classes: user defined constructors
you create the constructor to control how the obj is initialized rather than letting compiler give u the default one (may give u random values)
classes: this pointer
pointer in every class that points to current object that called the method
acc be able to assign the obj arributes to the obj to use them in methods
object’s attr = param attr (this → attr = attr) instead of attr = attr
*this = dereference/actual current obj
example1 :
public:
int x, y;
Class* e = this;
e→x = x;
OR
this→x = x;
OR
(*this).x = x;
used to:
resolve naming conflicts
return current obj for using multiple methods at once
passing current obj to other methods
classes: operator overloading
all operators can be manually overloaded
MyClass operatorX(const MyClass& other) const;
operators
operator+()
operator*()
operator«()
operator[]()
classes: destructors
auto called when obj gonna be destroyed
~className();
~className() {}
protected access specifiers
only can be accessed within the same class AND child classes
namespaces
used to avoid naming conflicts in big programs
allows things to have identical names AS LONG AS NAMESPACES ARE DIFF
to create a namespace
namespace Name{
int var = smth;
}
to access smth from certain namespace
Namespace::thing
NEVER USE using std namespace
c style casting
classes: copy constructors
classes: move constructors
templates