May 7, 1998

The Explicit Keyword

A constructor taking a single argument is by default an implicit conversion operator: class C { int I; //… public: C(int i);//constructor and implicit conversion operator //as well }; void f() { C c(0);c = 5; //implicit conversion of 5 to a C object and //then assignment } The compiler

Mem-initializer Evaluation Order

When initializing objects data members by a mem-initializer list, the compiler transforms the list into the order of the declaration of the data members in that class: class A { int &a; int b; public: A(int aa, int bb) : b(bb), a(aa) {} //1 }; Since a is declared in

Avoid Using malloc() and free() in C++

The use of malloc() and free() functions in a C++ file is not recommended and is even dangerous: 1. malloc() requires the exact number of bytes as an argument whereas new calculates the size of the allocated object automatically. By using new, silly mistakes such as the following are avoided:

Use Mem-initializer to Initialize Embedded Objects

If your class contains other object(s) as members, you should initialize the embedded object(s) in a mem-initializer list instead of assigning their values inside the class constructor: class Person { string name, address; //embedded objects int age; //preferred way to initialize embedded objects: Person(string n, string a) : name(n), address(a)

A Few Remarks About Inline Specifier

All member functions implemented within a class declaration are by default inline: //file: A.hclass A { int a; public: int Get_a() { return a; } //declaration + definition; //implicitly inline void Set_a(int aa) { a = aa; } //ditto void calc(int *result); //declaration only //…} Keep in mind, however, that

Debugger is not Being Invoked

When working on developing or debugging an app that is created via automation (i.e. ActiveX DLL), keep in mind the following: if you invoke that app from a calling program (exe) in a normal fashion and leave the calling program running, then run the app you are debugging in the

VB Hijacks the Registry

Be aware that the VB IDE hijacks the registry settings for your public classes when working on projects such as ActiveX DLLs and Controls. The IDE will temporarily replace (in the registry) the existing InProcServer32 for your class to a LocalServer32 entry pointing to the VB IDE version being run.

Using Dim Statement on Variant Arrays

When passing a variant array by reference, make sure to use Dim to declare the statement before using Redim. Example: Private Sub Command1_Click()Dim x as integer ReDim v(2) As Variant v(0) = “RIN” v(1) = “A” Call GetAuthors(v) Debug.print v(0,0)End SubSub GetAuthors(byref vArray as variant)Dim con As New ADODB.ConnectionDim rs

Efficiently Sharing Common Client Script Code Across Pages

When you have multiple web pages calling the same client script code, locate the shared script code in a separate file (e.g. Shared1.js) and reference the shared code in each page through the use of the SRC property of the The script file will be downloaded by the first page