Run Time with my overloading the = operator

I keep on getting a run time error at the end of my program. I was able to pinpoint the problem down to a single function test7(). If anyone could help me figure out why its keeps on causing a run time error and how to fix the problem would be much appreciated
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
  class String {
protected:
	int length;
	char* buf;
public:
	String();
	String(char*);
	String(char);
	String(int i);
	String(char c, int i);
	String(const String&);
	String& operator=(const String& s);
	int getLength();
	void print();
	~String();
};

String& String::operator=(const String& s){
	strcpy(buf, s.buf);
	length = s.length;
	return *this;
}

int main(){
       test7();
       return 0;
}

void test7(){
String s7("Sally Ride"), t7, u7;
	t7 = u7 = s7;
	s7.print();
	t7.print();
	u7.print();
	wait();
}

void wait(){
	char buf;

	cout << endl << "Press any key to continue." << endl;
	csis << endl << endl;
	cin.get(buf);
}
Do you think maybe in String::operator= you should make sure there's enough memory allocated to copy the other String?
Your right, I didn't realize I forgot to do that. Thanks
Topic archived. No new replies allowed.