Repository navigation
Expand file tree
/
Copy pathStr.h
More file actions
113 lines (79 loc) · 3.41 KB
/
Copy pathStr.h
File metadata and controls
113 lines (79 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef str_h
#define str_h
#include <string>
using namespace std;
class str {
private:
char* ptr;
/*
the two "const"s was add to insure that "len_local" won't change or modify anything.
this function calculates the length of a string from the type of "pointer to array of char"
this function is only used internally, not allowed to be called. thats why it is private.
*/
int len_local(const char* String) const;
public:
/*
default constractor
*/
str();
/*
When you add "const" to the constractor it is called a "Conversion Constructors", this tpye of constructor allows us to create an object using one value of another type.
"const" was added in the constractor to give us the ability to use the assignment operator "="
this constractor is used do (str x = "hi")
*/
str(const char* String);
/*
When you add "const" to the constractor it is called a "Conversion Constructors", this tpye of constructor allows us to create an object using one value of another type.
"const" was added in the constractor to give us the ability to use the assignment operator "="
this constractor is used do (str x = y), where y an object from class str;
this is called a copy constractor, it makes a copy of an object and puts it in an object from the same class
it is better in general to pass a reference to a constractor not a pointer
*/
str(const str& obj);
/*
string to str
*/
str(const string& String);
/*
this functions calculates the length of a string from the type str
*/
int len() const;
/*
converts our custom string to the conventional string from STLs
*/
string str2string() const;
/*
destractor
*/
~str();
/*
this operator returns "ptr" when the object gets called by name only.
we did not put a return type because this is a "conversion operators" and you should not put a return type while dealing with it
*/
operator const char* () const;
/*
Copy Assignment Operator
this is used to make (x = y) where x and y are defined before. and x and y are objects from class str
*/
void operator = (const str& obj);
void operator = (const char* String);
void operator = (const string& String);
str operator + (const str& obj) const;
str operator + (const char* string) const;
str operator + (const string& String) const;
str operator + (const int& num) const;
void operator += (const str& String);
void operator += (const string& String);
void operator += (const char* String);
void operator += (const int& num);
bool operator == (const str& obj) const;
/*
when you add the word "friend" before a function, the compiler understands that this function is not a method of the current class.
the operators of ">>" and "<<" take two inputs.
"friend" keyword is used to say that this function has access to the private and protected data members of this class
"istream" is the return type of this opperator.
why can't I make the operators of ">>" and "<<" local operators, we have to make them friend operators.
*/
friend std::istream& operator>>(std::istream& is, str& obj);
};
#endif