Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [c++]

C++ is a general-purpose programming language. Use this tag for questions about/utilizing C++. Do not also tag questions with [c] unless you have a good reason. C and C++ are different languages. Use a versioned tag such as [c++11], [c++20] etc. for questions specific to a standard revision.

c++
4229 votes
1 answer
3.2m 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 ...
1815 votes
40 answers
990k 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 do I fix and prevent these errors?
Luchian Grigore's user avatar
3407 votes
41 answers
1.2m views

What's the problem with "using namespace std;"?

I have heard using namespace std; is wrong, and that I should use std::cout and std::cin directly instead. Why is this? Does it risk declaring variables that share the same name as something in the ...
akbiggs's user avatar
  • 34.8k
2300 votes
19 answers
808k 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? (...
MainID's user avatar
  • 29.8k
695 votes
5 answers
99k views

Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) 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 ...
MAK's user avatar
  • 26.5k
2540 votes
8 answers
387k 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?
fredoverflow's user avatar
2470 votes
10 answers
1.0m views

What are the basic rules and idioms for operator overloading?

Note: This question and the original answers are from 2010 and partially outdated. Most of it is still good and helpful, but the original text no longer covers everything there is to know about C++ ...
sbi's user avatar
  • 223k
465 votes
10 answers
96k views

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

I posted a question with my code whose only #include directive was the following: #include <bits/stdc++.h> My teacher told me to do this, but in the comments section I was informed that I ...
Lightness Races in Orbit's user avatar
1167 votes
21 answers
306k views

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

I have the following code. #include <iostream> int * foo() { int a = 5; return &a; } int main() { int* p = foo(); std::cout << *p; *p = 8; std::cout << *...
1390 votes
10 answers
272k 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> // ...
MSalters's user avatar
  • 178k
659 votes
9 answers
93k views

Undefined, unspecified and implementation-defined behavior

What is undefined behavior (UB) in C and C++? What about unspecified behavior and implementation-defined behavior? What is the difference between them?
Zolomon's user avatar
  • 9,607
921 votes
17 answers
271k views

What is object slicing?

In C++, what is object slicing and when does it occur?
Frankomania's user avatar
  • 9,267
1067 votes
6 answers
348k 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, ...
Roger Lipscombe's user avatar
495 votes
11 answers
111k views

What is array-to-pointer conversion aka. decay?

What is array-to-pointer conversion aka. decay? Is there any relation to array pointers?
Vamsi's user avatar
  • 5,963
462 votes
10 answers
213k views

Why aren't variable-length arrays part of the C++ standard?

I haven't used C very much in the last few years. When I read this question today I came across some C syntax which I wasn't familiar with. Apparently in C99 the following syntax is valid: void foo(...
Andreas Brinck's user avatar

15 30 50 per page
1
2 3 4 5
6207