devxlogo

Tip Bank

Returning Keywords From a Map

A Hashmap is often used to store Keyword-Value pairs. The keywords are strings, so it is convenient to return a list of the keywords as an array of Strings. Fortunately,

Slicing in C++

Here is an example: class Shape {public: Shape() { }; virtual void draw() {};};class Circle : public Shape {private: int m_iRadius;public: Circle(int iRadius){ m_iRadius = iRadius; } virtual void draw()

Defining Static Data Members

Static data members must be explicitly defined exclusively in one source file. Here’s an example of a header file, such as MyClass.h: class MyClass { public: static int x; //

Using the ++ Operator

The ++ operator can be used in prefix and postfix. When it is used as a preifx , its value is evaluated first, then the statement is executed. For example:

Do Not Use Global Variables With Recursion

Global variables should never be used with recursion. It leads to stack overflow and program crash. Recursion works well only if it is in a self contained unit, using local

Using CoInitialize()

CoInitialize() should be called for each thread in the application that makes COM calls. Not just once at application startup.