The C++ Forum FAQ
A: The traditional C++ (pre-standard) headers define classes, values, macros, and functions in headers that have *.h extension. This includes non-standard STL headers with *.h extension (iostream.h, fstream.h, vector.h, etc.) and C headers with *.h extension (stdlib.h, stdio.h, etc.). Pre-standard headers have all the code in the global namespace.
A: C++ standard headers are those headers that are specified by the C++ standard.
A: The naming scheme for these files were specified based on the naming scheme of the traditional header files, but without the ending '.h'. For example, 'fstream.h' becomes 'fstream', 'memory.h' becomes 'memory' and so on.
A: The header iostream.h has never been part of the official C++ standard, which means any compiler that provides iostream.h, can do what ever it wants with it, and the compiler would still be considered compliant with the C++ standard.
A: The traditional ANSI C standard header files are prefixed with the letter 'c'. Thus 'stdio.h' has become 'cstdio', 'stdlib.h' is called 'cstdlib', 'math.h' is called 'cmath', 'time.h' is called 'ctime' and so on.
A: Assignment and comparison are not necessarily related, but we decided to handle them together because the mistakes made by programmers beginning with C++ have a common root, that is, the tendence to use a 'natural' syntax.
This actually is an issue only when working with C-style strings, i.e. 'char*'. The most common mistake is this:
Another mistake that is frequently made by beginners is something like this:
A: If you declare a class in your code the compiler normally needs to know some information about the used class like e.g. size. But if you just uses a pointer or a reference, the compiler doesn't need to know those information at that point since pointers or references are always the same size (4 bytes on a windows system). So you just need to tell the compiler that there will be a class - in this case called 'CSomeClass' - which will be used later by that declared pointer or reference.
In this case you can use the so-called 'forward declaration'...
A: Whenever you allocate memory with 'new', you have to free the memory using 'delete'. When you allocate memory with 'new', then use 'delete' without the brackets. You use 'new' to allocate an array of values (always starting at the index 0).
A: Because such a large piece of memory exceeds the stack size (a stack overflow). You need to allocate the memory on the heap instead:
double* x = new double;
A: Design Patterns represent solutions to problems what arise when developing software within a particular context.
A: Basically, there are three categories:
• Creational Patterns: deal with initializing and configuring classes and objects
• Structural Patterns: deal with decoupling the interface and implementation of classes and objects
• Behavioral Patterns: deal with dynamic interactions among societies of classes and objects
A: Answer is that if precision is less of a concern than storage, consider using type float for floating-point variables. Conversely, if precision is the most important criterion, use type double.
A: A random number generator needs to be seeded before use, or it will always generate the same list of random numbers. For example the C 'time()' function can be used for this:
|All times are GMT +5.5. The time now is 13:41.|