#include <iostream>
using namespace std;
//运算符重载
class Box {
private:
int length;
int width;
int high;
public:
int getLength() const {
return length;
}
void setLength(int length) {
Box::length = length;
}
int getWidth() const {
return width;
}
void setWidth(int width) {
Box::width = width;
}
int getHigh() const {
return high;
}
void setHigh(int high) {
Box::high = high;
}
//+运算符重载
Box operator+(const Box& b){
Box box;
box.length = this->length + b.length;
box.high = this->high + b.high;
box.width = this->width + b.width;
return box;
}
};
int main ()
{
Box box1, box2, box3;
box1.setHigh(100);
box1.setWidth(100);
box1.setLength(100);
box2.setWidth(200);
box2.setHigh(200);
box2.setLength(200);
box3 = box1 + box2;
cout << box3.getHigh() << "," << box3.getLength() << "," << box3.getWidth() << endl;
}
// 使用char数组定义字符串
char str1[3] = {'a', 'b', '\0'};//结尾必须加空字符标志\0,否则会被当成字符数组处理
char str2[] = "ab";//也可以这样定义,系统自动加上空白字符\0
// 使用string定义字符串
string c4 = "ab";