#include "iostream"
#include "string"
class CVector{
std::string *ptr;
public:
//Default constructor // 默认构造函数
CVector(){
ptr = new std::string;
}
//Constructor with parameters //带有一个参数的构造函数
CVector(std::string s):ptr(new std::string(s)){}
// Deconstructor
~CVector(){ //析构函数
std::cout << content() << std::endl;
std::cout << "release me" << std::endl;
delete ptr;
}
const std::string & content(){return *ptr;}
};
int main(){
CVector ca;
CVector cb("abc");
}
output:
abc
release me
release me