编译环境:linux,vs2012
Main.cpp
#include <iostream>
#include "String.h"
using namespace std;
int main()
{
String s1("hello"); //验证转换构造函数
s1.Display();
String s2(s1); //验证拷贝构造函数
s2.Display();
String s3;
s3 = s1; //"=" 运算符重载
s3.Display();
String s4;
s4 = "world"; //"="运算符重载
s4.Display();
cout << s4[4] << endl; //"[]"重载
s4 += s3; //"+="运算符重载
s4.Display();
String s5;
s5 = s1 + s3; //"+"运算符重载
s5.Display();
String s6("my cout");
cout << s6 << endl; //"<<"流运算符重载
String s7;
cin >> s7; //">>"流运算符重载
cout << s7 << endl;
char *newptr = static_cast<char *>(s2); //强制类型转换重载
cout << newptr << endl;
return 0;
}
String.h
#ifndef _STRING