12.05.2015 Views

type - David Vernon

type - David Vernon

type - David Vernon

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Classes and Objects<br />

Classes as Arguments and Return Values<br />

• Pass address of class object<br />

// PTROBJ: pointer parameter & return value<br />

#include <br />

#include <br />

#include “article.h”<br />

article *plargeobj(article *px) // functional spec<br />

{ article *p; // pointer<br />

p = new article; // new article<br />

p->codex++; // increment code<br />

strcpy(p->name, px->name); // copy name<br />

p->weight = 2 * px->weight; // double weight<br />

p->length = 2 * px->length; // double length<br />

return p; // return new obj.<br />

}<br />

// main to follow<br />

Copyright © 2007 <strong>David</strong> <strong>Vernon</strong> (www.vernon.eu)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!