586 Answered Questions for the topic C++

C++

09/22/19

Typedef function pointer?

I'm learning how to dynamically load DLL's but what I don't understand is this line typedef void (*FunctionFunc)();I have a few questions. If someone is able answer them I would be grateful.1.... more
C++

09/22/19

What does {0} mean when initializing an object?

When `{0}` is used to initialize an object, what does it mean? I can't find any references to `{0}` anywhere, and because of the curly braces Google searches are not helpful. Example code: ... more
C++

09/22/19

Static linking vs dynamic linking?

Are there any compelling performance reasons to choose static linking over dynamic linking or vice versa in certain situations? I've heard or read the following, but I don't know enough on the... more
C++

09/22/19

What does T&& (double ampersand) mean in C++11?

I've been looking into some of the new features of C++11 and one I've noticed is the double ampersand in declaring variables, like `T&& var`. For a start, what is this beast called? I wish... more
C++

09/22/19

Storing C++ template function definitions in a .CPP file?

I have some template code that I would prefer to have stored in a CPP file instead of inline in the header. I know this can be done as long as you know which template types will be used. For... more
C++

09/22/19

Detecting superfluous #includes in C/C++?

I often find that the headers section of a file get larger and larger all the time but it never gets smaller. Throughout the life of a source file classes may have moved and been refactored and... more
C++

09/22/19

What uses are there for "placement new"?

Has anyone here ever used C++'s "placement new"? If so, what for? It looks to me like it would only be useful on memory-mapped hardware.
C++

09/22/19

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... more
C++

09/21/19

What is the difference between g++ and gcc?

What is the difference between g++ and gcc? Which ones should be used for general c++ development?

09/21/19

Combined Assignment Operators

This is a silly program to help you practice with combined assignment operators, such as +=. Use ONLY these types of operators as you manipulate the user's lucky number by always using the number... more
C++

09/20/19

How do I find the length of an array?

Is there a way to find how many values an array has? Detecting whether or not I've reached the end of an array would also work.
C++

09/20/19

Can I use break to exit multiple nested for loops?

Is it possible to use the `break` function to exit several nested `for` loops? If so, how would you go about doing this? Can you also control how many loops the break exits?

09/19/19

C++ programming.

Algorithms -devising an efficient algorithm Write a function that is given an array of names and that removes duplicate names and keeps the remaining names in the order in which they first... more
C++

09/16/19

Why is it faster to process a sorted array than an unsorted array?

Here is a piece of C++ code that seems very peculiar. For some strange reason, sorting the data miraculously makes the code almost six times faster. <!-- language: lang-cpp --> #include... more
C++

09/16/19

Cycles in family tree software?

I am the developer of some family tree software (written in C++ and Qt). I had no problems until one of my customers mailed me a bug report. The problem is that the customer has two children with... more
C++

09/15/19

Why do people say there is modulo bias when using a random number generator?

I have seen this question asked a lot but never seen a true concrete answer to it. So I am going to post one here which will hopefully help people understand why exactly there is "modulo bias" when... more
C++

09/15/19

Easiest way to convert int to string in C++?

What is the easiest way to convert from `int` to equivalent `string` in C++. I am aware of two methods. Is there any easier way? (1) int a = 10; char *intStr = itoa(a); string str =... more
C++

09/15/19

Why have header files and .cpp files?

Why does C++ have header files and .cpp files?
C++

09/14/19

Why doesn't Java offer operator overloading?

Coming from C++ to Java, the obvious unanswered question is why didn't Java include operator overloading? Isn't `Complex a, b, c; a = b + c;` much simpler than `Complex a, b, c; a =... more
C++

09/14/19

How do you declare an interface in C++?

How do I setup a class that represents an interface? Is this just an abstract base class?
C++

09/14/19

Typedef function pointer?

I'm learning how to dynamically load DLL's but what I don't understand is this line typedef void (*FunctionFunc)(); I have a few questions. If someone is able answer them I would be... more
C++

09/14/19

Do the parentheses after the type name make a difference with new?

If 'Test' is an ordinary class, is there any difference between: Test* test = new Test; and Test* test = new Test();
C++

09/13/19

Why isn't sizeof for a struct equal to the sum of sizeof of each member?

Why does the `sizeof` operator return a size larger for a structure than the total sizes of the structure's members?
C++

09/08/19

Why use pointers?

I know this is a really basic question, but I've just started with some basic C++ programming after coding a few projects with high-level languages. Basically I have three questions: 1. Why use... more
C++

09/08/19

Why do we need virtual functions in C++?

I'm learning C++ and I'm just getting into virtual functions. From what I've read (in the book and online), virtual functions are functions in the base class that you can override in derived... 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.