Category Archive for "C++ Faq"

What is an undefined reference/unresolved external symbol error and how do I fix it?

When working with C++ programming, you may encounter an error message that says "undefined reference" or "unresolved external symbol". These are linker errors that us...

Why is "using namespace std;" considered bad practice?

In C++, the std (Standard) namespace is used to organize the elements of the Standard Library. It contains a large number of functions, classes, and other components...

Why can templates only be implemented in the header file?

Templates in C++ are a powerful feature that allows for the creation of reusable code. However, there is a restriction that templates can only be implemented...

Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?

When it comes to reading input from streams in C++, it's important to understand the correct approach to check for the end-of-file (EOF) condition. The question here pertains to th...

Understanding The Rule of Three in C++: Copy Constructor, Copy Assignment Operator, and Object Copying

When working with objects in C++, it is important to understand the concept of object copying. In some cases, you may need to create a copy of an existing object or p...

What are the basic rules and idioms for operator overloading?

Operator overloading is a powerful feature in C++ that allows you to redefine the behavior of an operator for user-defined types. It enables you to write code that is more expressi...

Why should I not #include <bits/stdc++.h>?

If you are a beginner in C++ programming, you might have come across the "#include <bits/stdc++.h>" directive in some code examples or tutorials. This directive is often reco...

Where and why do I have to put the "template" and "typename" keywords?

In C++ templates, the keywords "template" and "typename" are used to provide hints to the compiler in certain situations where it may not be able to deduce the correct meaning of a...

Understanding and Avoiding Object Slicing in C++

When working with inheritance in C++, it's important to understand the concept of object slicing and how it can affect your program's behavior. Object slicing occurs...

What are the rules about using an underscore in a C++ identifier?

In the world of C++, naming conventions play a crucial role in writing clean and maintainable code. One common naming convention is to use an underscore (_) as a pref...