Main Menu


Sponsored Links

  


  
  
Web Cartoon Maker: a Fun Way to Learn C++ Contents Previous Next

Accessing instance variables

You can read the values of an instance variable using the same syntax we used to write them:

double dX = MyPoint.dX;

The expression MyPoint.dX means “go to the object named MyPoint and get the value of dX”. In this case we assign that value to a local variable named dX. Notice that there is no conflict between the local variable named dX and the instance variable named dX. The purpose of dot notation is to identify which variable you are referring to unambiguously.

You can use dot notation as part of any C++ expression, so the following are legal.

Max.SetPos ( MyPoint.dX + 5.0, MyPoint.dY * 1.1 );

double dDistance =

Sqrt ( MyPoint.dX * MyPoint.dX + MyPoint.dY * MyPoint.dY );

In this sample code, the first line changes the position of a WCM character and second line calculates the distance of a point from cartoon's origin. Note that this code as written would not be part of a class definition. If it were, the distance variable would be written as MyPoint.dDistance .


Contents Previous Next
  
News

New Tales Animator Video by Alan Sturgess

Alan Sturgess shared an excellent video he made using Tales Animator! You can still download Tales Animator here. Unfortunately it is only available for Wi

...

Simple Online Character Designer

There is a prototype of simple online character designer available HERE. It is only a prototype, it does not contain many pieces yet but it can already generat

...

Book is updated

Now our book "Web Cartoon Maker: A Fun Way to Learn C++" is fully in synch with WCM 1.5! It is available for download and online reading HERE.

...

Web Cartoon Maker 1.5 is here!

Web Cartoon Maker 1.5 is finally here! You can download it HERE! Here is what was updated in version 1.5: Web Cartoon Maker Desktop Edition is now fully standal

...

read more news...


Poll