CS 4448 - Spring 1998
Object-Oriented Programming and Design
Lecture 7.2
Chapter 7
- Overloading new and delete uses static to share info.
- Removing methods from design interface via private.
Answers to Questions
- If you have pow(int,int) and pow(double,double) then you have a
problem when you say pow(2.0,3). Implicit conversion says 2.0
suggests using the double method and 3 suggests using the int
method. The method that should be called is ambigious. Change the
call to pow(2.0,(double)3) or pow((int)2.0,3).
- Keywords: true and false are reserved words and bool class uses
them. true is 1 and false is 0. bool test = 7 is converted to 1.
- Don't use NULL. It is defined as a macro in several dozen .h
files and can cause problems since definitions may not be the
same. const int NULL = 0; will result in warnings if the definition is
redefined but the proper solution is to use 0. Don't consider 0 to be
a hard coded integer but a special value.
- When using default values in methods you can not skip
values. (i.e. foo(2,3,4), foo(2,3), foo() are okay but foo(2,,4) is
not)
- The default new and delete do not clear memory. So, if you are
worried about security you should clear out data in memory in your
distructor or write your own delete.
- Lastly details on calling initializers and constructors for parent
class and instance variables on instance creation. P.139
Talk
Adam Jonathan Griff,
computer@griffmonster.com
Copyright © University of Colorado. All rights reserved.
Revised: March 2, 1998