Non-Type Template Parameters Template parameters are categorized into type parameters and non-type parameters. A type parameter is preceded by class or typename in the template list, while a non-type parameter is a compile-time constant that functions as a parameter for class or function templates a...
class FdMonitor::Internal { public: void unregister(int fd); void registerFd(int fd); std::vector<int> awaitEvents(); private: std::vector<int> watchList_; std::mutex listMutex_; std::pair<int, int> signalPipe_; }; The fault manifested in the unregister() routine: void FdMonitor::I...
In C++, a class declaration appearing empty to the programmer actually contains implicit machinery. The compiler synthesizes six special member functions to manage object lifecycle, enabling consistent initialization, copying, and cleanup behaviors without explicit boilerplate. Constructors Object i...
Bubble Sort Bubble sort operates by repeatedly stepping through the list, comparing adjacent elements, and swapping them if they are in the wrong order. This process causes the largest unsorted elements to migrate to their correct positions at the end of the array. While straightforward, its quadrat...
In standard 0/1 knapsack problems, the objective is often to determine the number of ways to fill a specific capacity by adding items. However, challlenges arise when we need to compute the number of valid combinations after excluding a specific item from an already calculated set. Let $F[j]$ repres...
Variables with const When applied to variables, the const qualifier prevents modification after initialization. const int MAX_SIZE = 100; MAX_SIZE = 200; // Compilation error Function Parameters Using const with function parameters ensures the arguemnts remain unmodified within the function scope. v...
Confusing & and *: Inverse Operations The unary operator & fetches the memory address of a variable, while * dereferences an address to access its stored value. They act as inverse operations. int val = 10; int* ptr; ptr = &val; std::cout << *ptr; // prints 10 Here, &val yields...
The Observer pattern is a behavioral design pattern that establishes a one-to-many dependency relationship between objects. When the state of one object changes, all dependent objects are automatically notified and updated. This pattern is particularly useful in scenarios where multiple objects need...
Header File #ifndef CHESSBOARDWIDGET_H #define CHESSBOARDWIDGET_H #include <QWidget> #include <QPainter> QT_BEGIN_NAMESPACE namespace Ui { class ChessBoardWidget; } QT_END_NAMESPACE class ChessBoardWidget : public QWidget { Q_OBJECT public: explicit ChessBoardWidget(QWidget *parent = nul...
Basic Definition An inline function is defined similarly to regular functions, with the addition of the inline keyword before the function signature. inline void logMessage(const char* msg) { std::cout << msg; } Why Use Inline Functions Original Purpose: To replace certain #define macro defini...