All Questions

4256
votes
1answers
1765471 views

The Definitive C++ Book Guide and List

This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the go from tut...
1076
votes
27answers
376253 views

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

What are undefined reference/unresolved external symbol errors? What are common causes and how to fix/prevent them? Feel free to edit/add your own.
1237
votes
13answers
317841 views

Why can templates only be implemented in the header file?

Quote from The C++ standard library: a tutorial and handbook: The only portable way of using templates at the moment is to implement them in header files by using inline functions. Why is this? ...
1719
votes
8answers
202379 views

What is The Rule of Three?

What does copying an object mean? What are the copy constructor and the copy assignment operator? When do I need to declare them myself? How can I prevent my objects from being copied?
439
votes
4answers
37526 views

Why is iostream::eof inside a loop condition considered wrong?

I just found a comment in this answer saying that using iostream::eof in a loop condition is "almost certainly wrong". I generally use something like while(cin>>n) - which I guess implicitly che...
1797
votes
34answers
575778 views

Why is "using namespace std" considered bad practice?

I've been told by others that writing using namespace std in code is wrong, and that I should use std::cout and std::cin directly instead. Why is using namespace std considered a bad practice? Is it ...
818
votes
20answers
238732 views

Can a local variable's memory be accessed outside its scope?

I have the following code. int * foo() { int a = 5; return &a; } int main() { int* p = foo(); cout << *p; *p = 8; cout << *p; } And the code is just running...
822
votes
5answers
102515 views

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

In templates, where and why do I have to put typename and template on dependent names? What exactly are dependent names anyway? I have the following code: template <typename T, typename Tail> /...
1739
votes
7answers
792285 views

What are the basic rules and idioms for operator overloading?

Note: The answers were given in a specific order, but since many users sort answers according to votes, rather than the time they were given, here's an index of the answers in the order in which they ...
761
votes
5answers
191231 views

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

It's common in C++ to name member variables with some kind of prefix to denote the fact that they're member variables, rather than local variables or parameters. If you've come from an MFC background,...

Previous Next