Tip Bank

DevX - Software Development Resource

Inheritance and Memory Allocation

Question: I can’t create an instance of the derived class using operator new. The base and the derived classes differ only by a virtual function. The error messages I receive

DevX - Software Development Resource

C++ objects

Question: How can I declare a constant object that is actually constant? Answer: Here’s an example: const Date d; //create a const Date object Note that you can only invoke

DevX - Software Development Resource

string.h

Question: I am a beginner with C++ programming. I was doing fine until I came to the string data type. Here is my problem: #include #include This gives me errors.

DevX - Software Development Resource

Calculating interest without floating types

Question: How can you caluculate interest using only integers and no double or floats? Answer: This question can be of interest for anyone who is confined to ineteger arithmetic. Many

DevX - Software Development Resource

Extract null-delimited strings

Most API function that return a string require that you pass a buffer where they can place the result as a null-terminated ANSI string (a.k.a. ASCIIZ string). The calling code

DevX - Software Development Resource

Count substrings with the Replace function

You can often use the Replace function in a smewhat unorthodox ways to simplify (and sometimes optimize) your code. For example, in order to count the number of occurrences of

DevX - Software Development Resource

Avoid append operations with the Replace function

I find the Replace function very useful when I want to avoid too many append operations just to insert non-printable characters. For example, the following statement: MsgBox “Disk not ready.”