devxlogo

Tip Bank

Using Enter to move to next field

Most MsDos programs used the Enter key to move from one field to the next one. You can easily simulate this behavior by setting the form’s KeyPreview property to True

SetFileSize – Trim or extend a file’s size

Option ExplicitPrivate Declare Function CreateFile Lib “kernel32” Alias “CreateFileA” (ByVal _ lpFileName As String, ByVal dwDesiredAccess As Long, _ ByVal dwShareMode As Long, lpSecurityAttributes As Any, _ ByVal dwCreationDisposition As

Avoid Unused Command Line Arguments

Many code wizards and automated source code generators synthesize the following main() template, even if the application doesn’t use command line arguments: int main(int argc, char* argv[]){ return 0;} This

Constructor Call Sequence

The constructors in a class hierarchy execute in the following sequence: base class constructors are called first, then member object’s constructors, and finally, the constructor of the derived class executes.

Disabling Further Derivation of a Class

Although the advantages of disabling further derivation of a class are often doubtable, C++ allows you to do that by declaring a class’s constructor and other special member functions private.

The auto Keyword

‘auto’ is undoubtedly the least used C++ keyword. This is because it’s always redundant. auto indicates local automatic storage type, for example: int main(){ auto int x; auto char s[10];}

Detecting the vptr’s Location

The precise location of the vptr (the pointer to the class’s table of virtual functions’ addresses) is implementation-dependent. Some compilers, e.g., Visual C++ and C++ Builder, place it offset 0,