Gang Of Coders
Home
About Us
Contact Us
All C++ Faq Solutions on Gang of Coders
Total of 129 C++ Faq Solutions
The Definitive C++ Book Guide and List
C++
C++ Faq
Does C++ support 'finally' blocks? (And what's this 'RAII' I keep hearing about?)
C++
Exception
Raii
Finally
C++ Faq
Is it possible to prevent stack allocation of an object and only allow it to be instantiated with 'new'?
C++
C++ Faq
Where and why do I have to put the "template" and "typename" keywords?
C++
Templates
Typename
C++ Faq
Dependent Name
Restrict variadic template arguments
C++
Templates
Variadic Templates
C++17
C++ Faq
How do I remove code duplication between similar const and non-const member functions?
C++
Class
Constants
Code Duplication
C++ Faq
Pointer to class data member "::*"
C++
Class
Pointers
C++ Faq
How to write C++ getters and setters
C++
Getter Setter
C++ Faq
When do I use a dot, arrow, or double colon to refer to members of a class in C++?
C++
C++ Faq
How do I prevent a class from being allocated via the 'new' operator? (I'd like to ensure my RAII class is always allocated on the stack.)
C++
Operator Overloading
C++ Faq
Constructor initialization-list evaluation order
C++
Gcc
C++ Faq
What are POD types in C++?
C++
Types
C++ Faq
What is the difference between public, private, and protected inheritance in C++?
C++
Inheritance
Encapsulation
Access Specifier
C++ Faq
How to pass objects to functions in C++?
C++
Pointers
Pass by-Reference
Pass by-Value
C++ Faq
Why does volatile exist?
C++
Volatile
C++ Faq
What is the <=> ("spaceship", three-way comparison) operator in C++?
C++
Operators
C++ Faq
C++20
Spaceship Operator
What is "rvalue reference for *this"?
C++
C++11
Move Semantics
C++ Faq
Qualifiers
Is the 'override' keyword just a check for a overridden virtual method?
C++
C++11
Overriding
Virtual Functions
C++ Faq
Do the parentheses after the type name make a difference with new?
C++
Constructor
Initialization
New Operator
C++ Faq
How come a non-const reference cannot bind to a temporary object?
C++
Reference
Constants
Temporary
C++ Faq
Undefined behavior and sequence points
C++
Undefined Behavior
C++ Faq
Sequence Points
Which kind of pointer do I use when?
C++
Pointers
C++11
Smart Pointers
C++ Faq
Why do I have to access template base class members through the this pointer?
C++
Templates
Inheritance
C++ Faq
What are the rules about using an underscore in a C++ identifier?
C++
Naming Conventions
Standards
C++ Faq
What are the new features in C++17?
C++
Standards
C++ Faq
C++17
What is the difference between a definition and a declaration?
C
Declaration
Terminology
Definition
C++ Faq
What is the curiously recurring template pattern (CRTP)?
C++
Templates
C++ Faq
Crtp
Why is it wrong to use std::auto_ptr<> with standard containers?
C++
Stl
Raii
Auto Ptr
C++ Faq
What does T&& (double ampersand) mean in C++11?
C++
C++11
Rvalue Reference
C++ Faq
Perfect Forwarding
Why should C++ programmers minimize use of 'new'?
C++
Memory Management
Heap Memory
New Operator
C++ Faq
Default constructor with empty brackets
C++
Constructor
Default Constructor
C++ Faq
Most Vexing-Parse
How to stop C++ console application from exiting immediately?
C++
Console
Exit
Terminate
C++ Faq
What do the following phrases mean in C++: zero-, default- and value-initialization?
C++
Initialization
C++ Faq
What is std::move(), and when should it be used?
C++
C++11
Move Semantics
C++ Faq
Stdmove
What are all the common undefined behaviours that a C++ programmer should know about?
C++
Undefined
Undefined Behavior
C++ Faq
What are the differences between a pointer variable and a reference variable in C++?
C++
Pointers
Reference
C++ Faq
What does the explicit keyword mean?
C++
Constructor
Explicit
C++ Faq
Explicit Constructor
Why is "using namespace std;" considered bad practice?
C++
Namespaces
Std
Using Directives
C++ Faq
Why use apparently meaningless do-while and if-else statements in macros?
C++
C
C Preprocessor
C++ Faq
Why is 'this' a pointer and not a reference?
C++
Pointers
Reference
This
C++ Faq
What is "Argument-Dependent Lookup" (aka ADL, or "Koenig Lookup")?
C++
Argument Dependent-Lookup
Name Lookup
C++ Faq
Which C++ idioms are deprecated in C++11?
C++
C++11
C++ Faq
std::wstring VS std::string
C++
String
Unicode
C++ Faq
Wstring
What is object slicing?
C++
Inheritance
C++ Faq
Object Slicing
Meaning of 'const' last in a function declaration of a class?
C++
Constants
Declaration
C++ Faq
Is the safe-bool idiom obsolete in C++11?
C++
C++11
Deprecated
C++ Faq
Safe Bool-Idiom
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
C++
C
Struct
Sizeof
C++ Faq
Why is volatile not considered useful in multithreaded C or C++ programming?
C++
C
Multithreading
Volatile
C++ Faq
What are the advantages of using nullptr?
C++
C++11
Null
C++ Faq
Nullptr
What does the C++ standard state the size of int, long type to be?
C++
C++ Faq
What is the proper declaration of main in C++?
C++
Function
Standards
Main
C++ Faq
Which iomanip manipulators are 'sticky'?
C++
C++ Faq
Overloading member access operators ->, .*
C++
Operator Overloading
C++ Faq
When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used?
C++
Pointers
Casting
C++ Faq
Why are C++ inline functions in the header?
C++
Inline
Theory
Language Design
C++ Faq
When can I use a forward declaration?
C++
Forward Declaration
C++ Faq
"std::endl" vs "\n"
C++
Coding Style
Iostream
C++ Faq
Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?
C++
Iostream
C++ Faq
How can I efficiently select a Standard Library container in C++11?
C++
C++11
C++ Faq
Why does std::getline() skip input after a formatted extraction?
C++
Input
Iostream
Istream
C++ Faq
Polymorphism in C++
C++
Polymorphism
C++ Faq
Why is `std::move` named `std::move`?
C++
C++11
Move Semantics
Rvalue Reference
C++ Faq
Why does the use of 'new' cause memory leaks?
C++
Pointers
Memory Leaks
New Operator
C++ Faq
Why is enum class preferred over plain enum?
C++
Class
Enums
C++ Faq
How to convert a number to string and vice versa in C++
C++
String
Type Conversion
Numeric
C++ Faq
When to make a type non-movable in C++11?
C++
C++11
Move Semantics
C++ Faq
Iterator invalidation rules for C++ containers
C++
Iterator
C++ Standard-Library
C++ Faq
Proper stack and heap usage in C++?
C++
Memory Management
Stack
Heap Memory
C++ Faq
What C++ Smart Pointer Implementations are available?
C++
Smart Pointers
C++ Faq
How to overload std::swap()
C++
Performance
Optimization
Stl
C++ Faq
Does const mean thread-safe in C++11?
C++
C++11
Thread Safety
Constants
C++ Faq
What is The Rule of Three?
C++
Copy Constructor
Assignment Operator
C++ Faq
Rule of-Three
What are the basic rules and idioms for operator overloading?
C++
Operators
Operator Overloading
C++ Faq
What is the copy-and-swap idiom?
C++
Copy Constructor
Assignment Operator
C++ Faq
Copy and-Swap
Different floating point result with optimization enabled - compiler bug?
C++
Optimization
G++
C++ Faq
What are transparent comparators?
C++
C++14
C++ Faq
Best practices for circular shift (rotate) operations in C++
C++
C
Rotation
Bit Manipulation
C++ Faq
What are the main purposes of using std::forward and which problems it solves?
C++
C++11
Rvalue Reference
C++ Faq
Perfect Forwarding
Why doesn't a simple "Hello World"-style program compile with Turbo C++?
C++
Turbo C++
C++ Faq
gcc/g++: "No such file or directory"
C++
C
Gcc
G++
C++ Faq
How do I use arrays in C++?
C++
Arrays
Pointers
Multidimensional Array
C++ Faq
What are template deduction guides and when should we use them?
C++
Templates
C++17
C++ Faq
Template Argument-Deduction
How do you serialize an object in C++?
C++
Serialization
Marshalling
C++ Faq
Why can templates only be implemented in the header file?
C++
Templates
Undefined Reference
C++ Faq
What is a smart pointer and when should I use one?
C++
Pointers
C++11
Smart Pointers
C++ Faq
What is move semantics?
C++
C++ Faq
C++11
Move Semantics
What is the correct answer for cout << a++ << a;?
C++
C++ Faq
C++11 rvalues and move semantics confusion (return statement)
C++
C++11
Move Semantics
Rvalue Reference
C++ Faq
What's the difference between "STL" and "C++ Standard Library"?
C++
Stl
Std
C++ Standard-Library
C++ Faq
How does the compilation/linking process work?
C++
Compiler Construction
Linker
C++ Faq
What is the point of function pointers?
C++
C
Function
Pointers
C++ Faq
Passing shared pointers as arguments
C++
C++11
Shared Ptr
C++ Faq
What exactly is the "as-if" rule?
C++
C
Optimization
C++ Faq
As If
What are the differences between struct and class in C++?
C++
Oop
Class
Struct
C++ Faq
Function with same name but different signature in derived class
C++
Function
Inheritance
Lookup
C++ Faq
When do extra parentheses have an effect, other than on operator precedence?
C++
C++11
Language Lawyer
Parentheses
C++ Faq
What are copy elision and return value optimization?
C++
Optimization
C++ Faq
Return Value-Optimization
Copy Elision
Copy constructor and = operator overload in C++: is a common function possible?
C++
Variable Assignment
Copy Constructor
C++ Faq
Why should I use a pointer rather than the object itself?
C++
C++11
Pointers
C++ Faq
Resolve build errors due to circular dependency amongst classes
C++
Compiler Errors
Circular Dependency
C++ Faq
Undefined behavior and sequence points reloaded
C++
Undefined Behavior
C++ Faq
Sequence Points
What is external linkage and internal linkage?
C++
C++ Faq
What is an undefined reference/unresolved external symbol error and how do I fix it?
C++
Linker Errors
Undefined Reference
C++ Faq
Unresolved External
What is a lambda expression in C++11?
C++
Lambda
C++11
C++ Faq
What is the difference between const int*, const int * const, and int const *?
C++
C
Pointers
Constants
C++ Faq
What is this weird colon-member (" : ") syntax in the constructor?
C++
Syntax
Constructor
C++ Faq
Ctor Initializer
Object destruction in C++
C++
Exception
Destructor
C++ Faq
Object Lifetime
Why aren't my include guards preventing recursive inclusion and multiple symbol definitions?
C++
Header Files
C++ Faq
Include Guards
Where do I find the current C or C++ standard documents?
C++
C
Standards
C++ Faq
Is the practice of returning a C++ reference variable evil?
C++
Reference
C++ Faq
Why would one replace default new and delete operators?
C++
Operator Overloading
New Operator
C++ Faq
Delete Operator
Why should I not #include <bits/stdc++.h>?
C++
Portability
Turbo C++
C++ Faq
Implementation Defined-Behavior
What XML parser should I use in C++?
C++
Xml Parsing
C++ Faq
How should I write ISO C++ Standard conformant custom new and delete operators?
C++
Operator Overloading
New Operator
C++ Faq
Delete Operator
What are rvalues, lvalues, xvalues, glvalues, and prvalues?
C++
Expression
C++ Faq
C++11
Why do we actually need Private or Protected inheritance in C++?
C++
Inheritance
Private
Protected
C++ Faq
Can a class member function template be virtual?
C++
Templates
Virtual Functions
Function Templates
C++ Faq
What does "cv-unqualified" mean in C++?
C++
C++ Faq
What are all the member-functions created by compiler for a class? Does that happen all the time?
C++
Member Functions
C++ Faq
What happens when an exception goes unhandled in a multithreaded C++11 program?
C++
Multithreading
Exception
C++11
C++ Faq
What is a "span" and when should I use one?
C++
C++20
C++ Faq
Cpp Core-Guidelines
Std Span
How to get IOStream to perform better?
C++
Optimization
Iostream
C++ Faq
C++ Standard-Library
shared_from_this causing bad_weak_ptr
C++
Boost
Shared Ptr
C++ Faq
How to implement classic sorting algorithms in modern C++?
C++
Algorithm
Sorting
C++14
C++ Faq
Why should I always enable compiler warnings?
C++
C
Warnings
Compiler Warnings
C++ Faq
Should I include <xxxx.h> or <cxxxx> in C++ programs?
C++
Include
C++ Faq
When is std::weak_ptr useful?
C++11
Shared Ptr
Weak Ptr
C++ Faq
What is the purpose of std::launder?
C++
Memory
C++17
C++ Faq
Stdlaunder
What changes introduced in C++14 can potentially break a program written in C++11?
C++
C++11
C++14
Language Lawyer
C++ Faq