devxlogo

Tip Bank

Overriding toString()

While definitely not required, overriding the toString() method in your classes will make their use much easier. Although java.land.Object provides basic implementation for this method, it is far from being

<fstream> Open Modes

The library defines the following open modes and file attributes: ios::app // appendios::ate // open and seek to file’s endios::binary // binary mode I/O (as opposed to text mode)ios::in //

Truncating a File Stream

Certain files need to be emptied every time an application opens them before it writes new data to them, for example, a per-session log file. One way to achieve this

Avoid Unnecessary Constructors and Destructors

Some programmers consistently define an empty constructor and destructor in their classes, as in: class A{//..public: A() {} ~A() {}}; This is totally useless. C++ guarantees that when a class

Avoid Empty Member Initialization Lists

Following yesterday’s tip, here’s another deprecated habit that programmers should avoid. Consider the following class hierarchy: class base{public: base();};class derived: public base{public: derived() : base() {/*some code*/} // superfluous}; The

Quick and Easy Queue

Listboxes provide suitable functionality to act as a quick queue. Create a listbox named ListMyQueue. Use this code to add to your Queue: Public Sub Enqueue(StringToAdd As String)If Len(String_to_Add) >

Clear Structure Data With one Assignment

User-defined types are useful when you need to store structured data that has no specific behavior. If you have associated behavior, you should encapsulate the data in its own class.

Create Captionless MDI Forms

Sometimes you might want an MDI form without any captions or buttons, such as in a game or acting as a background parent object. You can create a captionless MDI