Code:
class myclass
{
private:
int val;
char character;
public:
myclass (int newVal, char newChar);
void display (void);
};
// Constructor - called every time a new instance is generated or allocated with new:
myclass::myclass (int newVal, char newChar)
{
val = newVal;
character = newChar;
}
// Other member functions.
void myclass::display (void)
{
cout << val << ", " << character << ".\n";
}
main (void)
{
myclass c1 (34, 'f'); // Static object.
myclass *c2 = new myclass (78, 't'); // Dynamically allocated object.
c1.display ();
c2->display (); // Note the different way of accessing dynamic class members.
delete c2;
}