




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main topics in this course are object-orientation, objects and classes, overloading, inheritance, polymorphism, generic programming, exception handling, introduction to design patterns. This lecture includes: Binary, Operator, String, Ping, Solution, Buffer, Overhead, New, String, Set, Operator, Class, Public
Typology: Slides
1 / 28
This page cannot be seen from the preview
Don't miss anything!





















String{private:char^ *^ bufferPtr;
int^ size;
public:String();String(char
*^ ptr); void^ SetString(char
*^ ptr);
const^
char^ *
GetString(); ...};
Ping ” to “
Pong
character to be changed…} ►Possible solution:^ Call:
str2.SetString(“Pong”); This will delete the current buffer andallocate a new one
...public:void SetChar(char c, int pos);...
str1(“Ping”); str1.SetChar(‘o’,
// str1 is now changed to “
Pong
operator
int pos){
assert(pos>0 && pos<=size);return stringPtr[pos-1];}
►Must be a member function ►Any number of parameters can be specified ►Any return type can be specified ►Operator()
can perform any generic
operation
(int pos){
assert(pos>0 && pos<=size);return bufferPtr[pos-1];}
// g = ‘i’ s1(2) = ‘o’;cout << g << “\n”;cout << str.GetString();return 0;
index,
int^ subLength){ assert(index>
&&^ index+subLength-1<=size); char^ *
ptr^ =
new^ char[subLength+1]; for^ (int
i=0;^
i^ <^ subLength;
++i)
ptr[i]
=^ bufferPtr[i+index-1]; ptr[subLength]
=^ ‘\0’; String
str(ptr); delete
[]^ ptr; return
str;