586 Answered Questions for the topic C++
C++
08/06/19
Why does the order in which libraries are linked sometimes cause errors in GCC?
Why does the order in which libraries are linked sometimes cause errors in GCC?
C++
08/05/19
What is the meaning of prepended double colon "::"?
I found this line of a code in a class which I have to modify:
::Configuration * tmpCo = m_configurationDB;//pointer to current db
and I don't know what exactly means the double colon prepended...
more
C++
08/04/19
Advantages of using forward?
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...
more
C++
08/04/19
How to convert vector to array?
How do I convert a `std::vector<double>` to a `double array[]`?
C++
08/03/19
Difference between static and shared libraries?
What is the difference between static and shared libraries?
I use Eclipse and there are several project types including Static Libraries and Shared Libraries? Does one have an advantage over the...
more
C++
08/02/19
What are the barriers to understanding pointers and what can be done to overcome them?
Why are pointers such a leading factor of confusion for many new, and even old, college level students in C or C++? Are there any tools or thought processes that helped you understand how pointers...
more
C++
07/31/19
What is the difference between const int*, const int * const, and int const *?
I always mess up how to use `const int*`, `const int * const`, and `int const *` correctly. Is there a set of rules defining what you can and cannot do?
I want to know all the do's and all don'ts...
more
C++
07/30/19
What is the difference between the dot (.) operator and -> in C++?
What is the difference between the dot (.) operator and -> in C++?
C++
07/30/19
Why does changing 0.1f to 0 slow down performance by 10x?
Why does this bit of code,
const float x[16] = { 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8,
1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6};
const float z[16] = {1.123,...
more
C++
07/30/19
How do I execute a command and get output of command within C++ using POSIX?
I am looking for a way to get the output of a command when it is run from within a C++ program. I have looked at using the system() function, but that will just execute a command. Here's an example...
more
C++
07/29/19
Pointer vs. Reference?
What would be better practice when giving a function the original variable to work with:
unsigned long x = 4;
void func1(unsigned long& val) {
val = 5;
}
func1(x);
or:
...
more
C++
07/28/19
Initialization of a normal array with one default value?
[C++ Notes: Array Initialization](http://www.fredosaurus.com/notes-cpp/arrayptr/array-initialization.html) has a nice list over initialization of arrays. I have a int array[100] = {-1};expecting...
more
C++
07/28/19
How to check that an element is in a std::set?
How do you check that an element is in a set?
Is there a simpler equivalent of the following code:
myset.find(x) != myset.end()
C++
07/27/19
When to use extern in C++?
I'm reading "Think in C++" and it just introduced the `extern` declaration. For example:
extern int x;
extern float y;
I think I understand the meaning (declaration without definition), but...
more
C++
07/27/19
What do single quotes do in C++ when used on multiple characters?
I'm curious about this code:
cout << 'test'; // Note the single quotes.
gives me an output of `1952805748`.
My question: Is the output an address in memory or something?
C++
07/27/19
Why use apparently meaningless do-while and if-else statements in macros?
In many C/C++ macros I'm seeing the code of the macro wrapped in what seems like a meaningless `do while` loop. Here are examples.
#define FOO(X) do { f(X); g(X); } while (0)
#define FOO(X) if...
more
C++
07/26/19
How to get rid of `deprecated conversion from string constant to ‘char*’` warnings in GCC?
So I'm working on an exceedingly large codebase, and recently upgraded to gcc 4.3, which now triggers this warning:
> warning: deprecated conversion from string constant to ‘char*’
Obviously,...
more
C++
07/25/19
unsigned int vs. size_t?
I notice that modern C and C++ code seems to use `size_t` instead of `int`/`unsigned int` pretty much everywhere - from parameters for C string functions to the STL. I am curious as to the reason...
more
C++
07/23/19
When to use dynamic vs. static libraries?
When creating a class library in C++, you can choose between dynamic (`.dll`, `.so`) and static (`.lib`, `.a`) libraries. What is the difference between them and when is it appropriate to use which?
C++
07/23/19
Check if a string contains a string in C++?
I have a variable of type `std::string`. I want to check if it contains a certain `std::string`. How would I do that?
Is there a function that returns true if the string is found, and false if it...
more
C++
07/22/19
Differences between C++ string == and compare()?
I just read some recommendations on using
std::string s = get_string();
std::string t = another_string();
if( !s.compare(t) )
{
instead of
if( s == t )
{
I'm almost always...
more
C++
07/21/19
Static constant string (class member)?
I'd like to have a private static constant for a class (in this case a shape-factory).
I'd like to have something of the sort.
class A {
private:
static const string RECTANGLE =...
more
C++
07/21/19
Are == and != mutually dependent?
I'm learning about operator overloading in C++, and I see that `==` and `!=` are simply some special functions which can be customized for user-defined types. My concern is, though, why are there...
more
C++
07/20/19
Struct Constructor in C++?
Can a `struct` have a constructor in C++?
I have been trying to solve this problem but I am not getting the syntax.
C++
07/19/19
When should you use constexpr capability in C++11?
It seems to me that having a "function that always returns 5" is breaking or diluting the meaning of "calling a function". There must be a reason, or a need for this capability or it wouldn't be in...
more
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.