Title: Daily Comment Slides
1Daily Comment Slides
2for(int i0 iltcount i) VS.
for(int i1 iltcount i) const int
MAX_SIZE1000 VS. define MAX_SIZE
1000 NULL equivalent to 0 //often used for
pointers int x0, y1, z // not good
practice Creating a pointer does not allocate
space for the actual variable int p cin gtgt
p Other than the literal specification of a
string xyz, there is no built-in language
facility to manipulate strings, only chars. char
string150, string250 .. string1 string2
//NO if (string1string2)
//NO You must use standard C library functions to
manipulate them (strcmp, strcpy)
3chk1.SetCheck(100 ,strcpy(desta,srca), 123.45f ,
strcpy(destb,srcd)) ---- cout ltlt "Check
Number" ltlt "\t" ------ void CCheckcharcpy(cha
r s1, char s2,const int MAX) if(
strlen(s2) lt (unsigned) MAX ) strcpy(s1,s2) e
lse char x s1 char y s2 for(int
i0 i lt MAX i, x, y) x y x
'\0' -------- arrayptr array0
equivalent to arrayptr array --------- C
CheckCCheck() _number 0
strcpy(_payee, "") _amount 0.0f
strcpy(_date,"00/00/0000") _voided false
4 CCheck checks30 CCheck chk_ptr
checks chk_ptr-gtSetCheck(Fats Waller, 23.5F,
6/12/2001) chk_ptr-gtSetCheck(Bum Phillips,
123.5F, 7/15/2001)
5(1)
file c.cpp
file globals.h
ifndef _GLOBALS_H_ endif
include globals.h include b.h . . .
ifndef _GLOBALS_H_ define _GLOBALS_H_ const int
a 5 const int PI3.14 . . . endif
ifndef _GLOBALS_H_ endif
preprocessor
file b.h
include globals.h . . .
CCheck chk4 chk0.SetCheck(CCheckGetCheckNum
(), "Bill Jones", 123.45F, "5/4/2002") chk1.Set
Check(CCheckGetCheckNum(), "Fats Waller",
25.6F, "6/12/2001") chk2.SetCheck(CCheckGetCh
eckNum(), "Bum Phillips", 432.12F,
"11/5/2001") chk3 chk0 //check number
incremented twice unless call-by-reference CCheck
_pNum GetCheckNum() CCheck
CCheckoperator(CCheck op2) _pNum
GetCheckNum()
(2)
(3)
Use my homework answers as a code base if that
makes things smoother.
(4)
Visual C path for include ltfilename.hgt MenuPr
oject SubmenuSettings TabC/C -
CategoryPreprocessor Edit FieldAdditional
Include Directories ------.\
6(1) Opinion only Casts via (type) are still a
bit clearer syntax-wise to me in a real statement
so I still use them. I do sacrifice the
type-checking for dynamic cast but I mostly find
it not that useful in code Ive
done. ((CCheck)ptr)-gtShow() // a
bit more readable dynamic_castltDerived gt
(ptr)-gtShow() not the same as
(CCheck)ptr-gtShow() (2) Recommendation only
If you use initializers in one constructor in a
class, use them for all other overloaded ones as
well.
7Use RTTI for template functions or classes to
limit exposure to unexpected types check for
certain unhandled times or limit to certain types
via RTTI. Get and Set syntax, data structure
like classes int _limit obj.SetLimit(int
limit) int limit obj.Limit() //
alternatively GetLimit() Why use virtual
destructors
after new
ptr
class base base() base()
main() derived obj base ptr
ptr new derived delete ptr
k
after delete
class derived public base derived()knew
int derived() delete k int k
deleted
deleted
not deleted!
81) AutoPtrs not fully supported to the language
spec in VC version 6 2) Polymorphic behavior
of RTTI seems to have problems when you use
precompiled headers in VC 3) templa
te ltclass numgt class MyMath // this is
more typical than putting on one line. template
ltclass numgt num MyMathltnumgtSquared(num x) 4)
RTTI for templates is a good way to limit testing
to known good types