Category Archives: C++

The difference between copy construct function and assign function of a class

1. The copy construct function creates a new object, while the assign function assigns an object to an existed object. 2. The assign function needs to check if the assignment source and destination are the same, while the copy construct … Continue reading

Posted in C++ | Leave a comment

Use reference as a return type

Using reference as a return type returns the address of an object, which can be a left value. 1. The stream operator << and >> return a reference type. istream& operator>> (bool& val ); ostream& operator<< (bool val); Thanks to … Continue reading

Posted in C++ | Leave a comment

The usage of volatile

1. The register in hardware. 2. The non-auto variable which interrupt procedure may visit. 3. The variable shared by multi-threads.

Posted in C++ | Leave a comment

Const in C++

The const is used to define a readable variable or object, which can not be modified. It has the following effect: 1.  To define a constant, similar like define: const int a=3; int const a=3; 2. Applied to pointer: Remember: … Continue reading

Posted in C++ | Leave a comment

The difference between typedef and define

1. The typedef is intended to make alias of a variable type. The define is mainly to name a constant. C++: 1 typedef unsigned int UINT; 2 typedef unsigned char BYTE; 3  4 #define MAX_LENGTH(100) 5 #define SUB(x,y) ((x)*(y)) 2. The typedef is function during … Continue reading

Posted in C++ | Leave a comment

Write a Min macro

C++: 1 #define Min(a,b) ((a)<(b)?(a):(b))

Posted in C++ | Leave a comment

The difference between a macro and a function.

1. The macro consume the pre-process time and function consume compile time. The macro will not immediate invoke function call. 2. The macro does not have return value, it will only substitute statement. 3. The parameter in macro does not … Continue reading

Posted in C++ | Leave a comment