Introduction to OOP: Chapter 4: Messages, Instances, and Initialization: [next] [previous] [audio] [real] [text]

Constructors

In C++ and Java a Constructor is a member function with the same name as the class. Can take argument lists, like other functions.

A constructor is automatically invoked when an object is created.

class Card {
public:
		// constructor
	Card (Suits sv, int rv) {
		s = sv; // set suit
		r = rv; // set rank
		faceup = false; // start out face down
	}
	...

};

Intro OOP, Chapter 4, Slide 12