L16 - Classes - Object Oriented Design Where do we stand...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Object Oriented Design Where do we stand now? • Class is a “blueprint” for objects – an ADT • Class Definition – placed in header file – Indicates its name along with: Its data members or instance variables (declarations of these) Its methods (prototypes for these) Indication as to the accessibility of each member element (public, private, protected) – Usually does not contain any code for implementation of the methods • Definition of methods – Placed in a source file (that is, a .cpp file) – Syntax is <classname>::<methodname> ( <args>){…. .};
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object Oriented Design Where do we stand now? (cont) •D e f i n i n g a class does not make an instance of that class – the definition just makes the blueprint for objects of that class To make an instance of a class: A declaration of an object of a class causes space to be reserved for it and the default constructor to be invoked (but be careful with objects that have dynamically allocated members, as we shall see) weather today; // saves space for a weather object and initializes it If we declare a pointer to an object of a class and we want to initialize that pointer to point to a new object, we have to use
Background image of page 2
Class Scope – data members and function members have class scope this means that they can be accessed within the class’s methods by name – outside a class’s scope, class members cannot be referenced by name – but the public members can be referenced by a “handle” an object name a reference to an object (remember – this is an alias) a pointer or tracking handle to an object Practicalities: – access through an object name or through a reference use the dot (.) access operator – access through a pointer or tracking handle to the object uses the arrow (->) access operator Some variables (those defined within a method) have only method scope those members that are public functions or methods are the things that present to the class’s clients a view of the services that the class provides – Functions should perform only one task
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Constructors Instances of classes are initialized by constructors – Constructors initialize the instance variables of objects – They always have the same name as the class for which they are defined – Return types are not allowed for constructors There could be multiple constructors for a class - overloaded constructors can be used to provide different ways to initialize objects of a class Even if the constructor does not do so explicitly, all data members are initialized to something by Visual C++ 2005, but it may not be predictable – Primitive numeric types are “supposed” to be set to 0 but be careful – sometimes doubles that are “set to 0” aren’t really 0 but very
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/08/2008 for the course EE 361 taught by Professor Conry during the Spring '08 term at Clarkson University .

Page1 / 25

L16 - Classes - Object Oriented Design Where do we stand...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online