






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







class Stock { public: int getShares() const; double getShareValue() const; ... }; // in Stock.cpp: bool operator<(const Stock& s1, const Stock& s2) { ... what should go here??? } CPSC 223, Fall 2010 3
Lets add a “<” operator to our Stock class … class Stock { public: int getShares() const; double getShareValue() const; ... }; // in Stock.cpp: bool operator<(const Stock& s1, const Stock& s2) { double v1 = s1.getShares() * s1.getShareValue(); double v2 = s2.getShares() * s2.getShareValues(); return v1 < v2; } CPSC 223, Fall 2010 4 Note similar to “worthMore” function
Stock s2(s1);
int x;
x = 5; CPSC 223, Fall 2010 19 memory locaNon @111 to hold an int 5 value placed in the memory locaNon @
int x; int* xptr;
x = 5; xptr = &x; CPSC 223, Fall 2010 20 memory locaNon @ to hold an int 5 value placed in the memory locaNon @ memory locaNon @ to hold an int address @ x’s address placed in the memory locaNon @
int x = 5; int* xptr = &x; *xptr = 6; CPSC 223, Fall 2010 21 5 value placed in the memory locaNon @ @ x’s address placed in the memory locaNon @ 6
int* xptr = new int; *xptr = 5; CPSC 223, Fall 2010 22 value placed in the memory locaNon @ @ x’s address placed in the memory locaNon @ 5