c++-faq Questions
12
Solved
Many C++ books contain example code like this...
std::cout << "Test line" << std::endl;
...so I've always done that too. But I've seen a lot of code from working developers like this...
24
Solved
I'm coming from a Java background and have started working with objects in C++. But one thing that occurred to me is that people often use pointers to objects rather than the objects themselves, fo...
12
Solved
I've just finished listening to the Software Engineering radio podcast interview with Scott Meyers regarding C++11. Most of the new features made sense to me, with the exception of one. I still don...
Breban asked 23/6, 2010 at 22:46
10
Solved
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 ...
Disarray asked 4/8, 2015 at 17:57
5
I'd like to ensure my RAII class is always allocated on the stack.
How do I prevent a class from being allocated via the 'new' operator?
Mckenna asked 24/9, 2008 at 1:18
14
8
In perfect forwarding, std::forward is used to convert the named rvalue references t1 and t2 to unnamed rvalue references. What is the purpose of doing that? How would that affect the called functi...
Underglaze asked 27/8, 2010 at 6:59
20
Solved
I stumbled upon Stack Overflow question Memory leak with std::string when using std::list<std::string>, and one of the comments says this:
Stop using new so much. I can't see any reason you ...
Mckenzie asked 28/6, 2011 at 0:8
9
Solved
I wrote a simple program that sets a value to a variable and then prints it, but it is not working as expected. My program has only two lines of code:
uint8_t a = 5;
cout << "value is &...
Tardigrade asked 24/10, 2013 at 9:30
36
Solved
Lately, I've been trying to learn C++ from this website. Unfortunately whenever I try to run one of the code samples, I see that program open for about a half second and then immediately close. Is ...
10
Solved
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>...
Nimiety asked 4/3, 2009 at 11:56
10
Solved
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>...
Subaxillary asked 4/3, 2009 at 11:56
10
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++...
Overby asked 12/12, 2010 at 12:44
10
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++...
Kati asked 12/12, 2010 at 12:44
6
Solved
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 backgrou...
Kantos asked 23/10, 2008 at 7:2
1
Solved
There are plenty of questions and answers relating to C++ global variables, such as:
static and extern global variables in C and C++
Global variables and constexpr (inline or not?)
Is there any se...
Riser asked 29/8, 2023 at 11:0
4
Solved
Recently I've gotten suggestions to use span<T>'s in my code, or have seen some answers here on the site which use span's - supposedly some kind of container. But - I can't find anything like...
Cassondracassoulet asked 16/8, 2017 at 22:15
6
Since this question gets asked about every week, this FAQ might help a lot of users.
How to convert an integer to a string in C++
how to convert a string into an integer in C++
how to convert a f...
Sells asked 13/3, 2011 at 14:47
4
Solved
I have a constructor that takes some arguments. I had assumed that they were initialized in the order listed, but in one case, it appears they were being initialized in reverse, resulting in an abo...
Zahn asked 7/8, 2009 at 4:0
19
Solved
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...
Enforce asked 30/1, 2009 at 10:6
21
Solved
I often hear that when compiling C and C++ programs I should "always enable compiler warnings". Why is this necessary? How do I do that?
Sometimes I also hear that I should "treat warnings as err...
Corvus asked 8/9, 2019 at 14:20
14
In C++03, an expression is either an rvalue or an lvalue.
In C++11, an expression can be an:
rvalue
lvalue
xvalue
glvalue
prvalue
Two categories have become five categories.
What are these new c...
Undersell asked 30/8, 2010 at 15:2
17
Solved
What is the difference between public, private, and protected inheritance in C++?
Proline asked 13/5, 2009 at 20:47
19
Solved
I came across this strange code snippet which compiles fine:
class Car
{
public:
int speed;
};
int main()
{
int Car::*pSpeed = &Car::speed;
return 0;
}
Why does C++ have this pointer to...
44
What is the difference between a pointer variable and a reference variable?
1 Next >
© 2022 - 2025 — McMap. All rights reserved.