All Questions

4257
votes
1answers
1738552 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...
1052
votes
27answers
370354 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.
1206
votes
13answers
311451 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? ...
1698
votes
8answers
199252 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?
432
votes
4answers
36914 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...
1758
votes
34answers
564679 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 ...
802
votes
20answers
237330 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...
813
votes
5answers
100847 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> /...
1733
votes
7answers
787415 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 ...
753
votes
5answers
189047 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