What does purpose use #ifdef and #if in C++

The meaning of #ifdef is that the code inside the block will be included in the compilation only if the mentioned preprocessor macro is defined. Similarily #if means that the block will be included only if the expression evaluates to true (when replacing undefined macros that appears in the expression with 0). One important point here is that the … Read more

Convert float to std::string in C++

Unless you’re worried about performance, use string streams: If you’re okay with Boost, lexical_cast<> is a convenient alternative: Efficient alternatives are e.g. FastFormat or simply the C-style functions.

how does the ampersand(&) sign work in c++?

To start, note that is a special pointer ( == memory address) to the class its in. First, an object is instantiated: Next, a pointer is instantiated: Next, the memory address of a is assigned to the pointer b: Next, the method CDummy::isitme(CDummy &param) is called: A test is evaluated inside this method: Here’s the tricky part. param is an … Read more

Class name does not name a type in C++

The preprocessor inserts the contents of the files A.h and B.h exactly where the include statement occurs (this is really just copy/paste). When the compiler then parses A.cpp, it finds the declaration of class A before it knows about class B. This causes the error you see. There are two ways to solve this: Include B.h in A.h. It is generally a good idea to include header files … Read more

Windows 7 exception code: 0xc0000409

I have a C++ windows application that was done by another programmer, that I had to remove one line of code. After rebuilding the application with visual studio 2013 it crashes with this in the event log: The application uses QT 4.7.4, and compiles with no errors. I am an embedded systems programmer and have … Read more

Initializing a two dimensional std::vector

Use the std::vector::vector(count, value) constructor that accepts an initial size and a default value: If a value other than zero, say 4 for example, was required to be the default then: I should also mention uniform initialization was introduced in C++11, which permits the initialization of vector, and other containers, using {}:

Why there is no pop_front method in C++ std::vector?

Because a std::vector has no particular feature regarding inserting elements at the front, unlike some other containers. The functionality provided by each container makes sense for that container. You probably should be using a std::deque, which is explicitly good at inserting at the front and back. Check this diagram out.

‘was not declared in this scope’ error

The scope of a variable is always the block it is inside. For example if you do something like The solution is to define y outside of the if blocks In your program you have to move the definition of y and c out of the if blocks into the higher scope. Your Function then … Read more

Is C++ an Object Oriented language?

C++ is usually considered a “multi-paradigm” language. That is, you can use it for object-oriented, procedural, and even functional programming. Those who would deny that C++ is OO generally have beef with the fact that the primitive types are not objects themselves. By this standard, Java would also not be considered OO. It is certainly … Read more