I am stuck on this problem

Hi everyone,

I have been racking my brain for a couple days now on this homework assignment and I am still lost. This chapter is about memory management.


Here is the question

Continue implementation of the String class. Add each of the following

1. A constructor String(int n, char c) that initializes the string with n copies of the character c

2. The + operator to perform concatenation of two String objects.

3. the function call operator so that s(int start, int length) returns a substring starting at the given position of the given size.


those are the 3 problems I am having with this assignment, I can figure out the rest on my own

this is what my code looks like

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
 class String
{
public:
	String();//constructor
	String(const char p[]);//simple constructor
	String(const String& right);//copy constructor
	~String();//destructor
	String& operator=(const String& right); //assignment operator
	String& operator+=(const String& right);
	int length() const;
	char& operator[](int index);
	char operator[](int index) const;


	//exersise 15.3 begins here
	
	String(int n, char c);//constructor initializes the string with n copies of c

	string operator+(const String& right);//concatenate two strings

	int compare(String);//compares if string is lexicographically less than, equal to, or greater than argument.

	void resize(int n, char c);//changes the size of the string to n, either truncating characters from the end, or inserting new copies of character c

	string operator()(const String& right);//returns a substring starting at the given position of the given size

	//ends here


private:
	char* buffer;
	int len;
};


Since I have to overload the + and the () operators how can I use another class object if member functions of a class only accept one parameter?
I have understood nothing. What is the problem? For example the function call operator can be declared as

String operator ()( int start, int length ) const;
By the way string!=String. See line 19 and 25
thanks for the input guys, after taking a small break I realized how easy this assignment is. I have been fasting and concentrating can be difficult.
Topic archived. No new replies allowed.