Thinking_in_C___2.rar

源代码在线查看: strings.h

软件大小: 3962 K
上传用户: fairbank
关键词: Thinking_in_C
下载地址: 免注册下载 普通下载 VIP

相关代码

				//: C13:Strings.h
				// From Thinking in C++, 2nd Edition
				// at http://www.BruceEckel.com
				// (c) Bruce Eckel 1999
				// Copyright notice in Copyright.txt
				// Simple string class
				// Can only be built on the heap
				#ifndef STRINGS_H_
				#define STRINGS_H_
				#include 
				#include 
				
				class String {
				  char* s;
				  String(const char* S) {
				    s = new char[strlen(S) + 1];
				    std::strcpy(s, S);
				  }
				  // Prevent copying:
				  String(const String&);
				  void operator=(String&);
				public:
				  // Only make Strings on the heap:
				  friend String* makeString(const char* S) {
				    return new String(S);
				  }
				  // Alternate approach:
				  static String* make(const char* S) {
				    return new String(S);
				  }
				  ~String() { delete s; }
				  operator char*() const { return s;}
				  char* str() const { return s; }
				  friend std::ostream&
				    operator				      return os 				  }
				};
				#endif // STRINGS_H_ ///:~
							

相关资源