Other function declaration
Access Modifiers:
class MyClass {
public:
void publicFunc() { /* Accessible from anywhere */ }
protected:
void protectedFunc() { /* Accessible within the class and derived classes */ }
private:
void privateFunc() { /* Accessible only within the class */ }
};Const Correctness
class MyClass {
public:
int getValue() const { return value_; } // Can be called on constant objects
void setValue(int newValue) { value_ = newValue; } // Cannot be called on constant objects
private:
int value_;
};Virtual Functions
class Base {
public:
virtual void func() { std::cout << "Base::func()\n"; }
};
class Derived : public Base {
public:
void func() override { std::cout << "Derived::func()\n"; }
};Override and Final
Static Functions
Inline Functions
Explicit Constructor
Default Arguments
Function Overloading
Function Templates
Run it here.
Last updated