#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
using namespace std;
int main()
{
string st = "I love xing";
vector<string> vc ;
vc.push_back(move(st));
cout<<vc[0]<<endl;
if(!st.empty())
cout<<st<<endl;
return 0;
}
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
using namespace std;
int main()
{
string st = "I love xing";
vector<string> vc ;
vc.push_back(st);
cout<<vc[0]<<endl;
if(!st.empty())
cout<<st<<endl;
return 0;
}
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
using namespace std;
class Str{
public:
char *value;
Str(char s[])
{
cout<<"调用构造函数..."<<endl;
int len = strlen(s);
value = new char[len + 1];
memset(value,0,len + 1);
strcpy(value,s);
}
Str(Str &v)
{
cout<<"调用拷贝构造函数..."<<endl;
this->value = v.value;
}
~Str()
{
cout<<"调用析构函数..."<<endl;
if(value != NULL)
delete[] value;
}
};
int main()
{
char s[] = "I love BIT";
Str *a = new Str(s);
Str *b = new Str(*a);
delete a;
cout<<"b对象中的字符串为:"<<b->value<<endl;
delete b;
return 0;
}
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
using namespace std;
class Str{
public:
char *value;
Str(char s[])
{
cout<<"调用构造函数..."<<endl;
int len = strlen(s);
value = new char[len + 1];
memset(value,0,len + 1);
strcpy(value,s);
}
Str(Str &v)
{
cout<<"调用拷贝构造函数..."<<endl;
int len = strlen(v.value);
value = new char[len + 1];
memset(value,0,len + 1);
strcpy(value,v.value);
}
~Str()
{
cout<<"调用析构函数..."<<endl;
if(value != NULL)
{
delete[] value;
value = NULL;
}
}
};
int main()
{
char s[] = "I love BIT";
Str *a = new Str(s);
Str *b = new Str(*a);
delete a;
cout<<"b对象中的字符串为:"<<b->value<<endl;
delete b;
return 0;
}
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
using namespace std;
class Str{
public:
char *value;
Str(char s[])
{
cout<<"调用构造函数..."<<endl;
int len = strlen(s);
value = new char[len + 1];
memset(value,0,len + 1);
strcpy(value,s);
}
Str(Str &v)
{
cout<<"调用拷贝构造函数..."<<endl;
this->value = v.value;
v.value = NULL;
}
~Str()
{
cout<<"调用析构函数..."<<endl;
if(value != NULL)
delete[] value;
}
};
int main()
{
char s[] = "I love BIT";
Str *a = new Str(s);
Str *b = new Str(*a);
delete a;
cout<<"b对象中的字符串为:"<<b->value<<endl;
delete b;
return 0;
}
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
using namespace std;
class Str{
public:
char *str;
Str(char value[])
{
cout<<"普通构造函数..."<<endl;
str = NULL;
int len = strlen(value);
str = (char *)malloc(len + 1);
memset(str,0,len + 1);
strcpy(str,value);
}
Str(const Str &s)
{
cout<<"拷贝构造函数..."<<endl;
str = NULL;
int len = strlen(s.str);
str = (char *)malloc(len + 1);
memset(str,0,len + 1);
strcpy(str,s.str);
}
Str(Str &&s)
{
cout<<"移动构造函数..."<<endl;
str = NULL;
str = s.str;
s.str = NULL;
}
~Str()
{
cout<<"析构函数"<<endl;
if(str != NULL)
{
free(str);
str = NULL;
}
}
};
int main()
{
char value[] = "I love zx";
Str s(value);
vector<Str> vs;
//vs.push_back(move(s));
vs.push_back(s);
cout<<vs[0].str<<endl;
if(s.str != NULL)
cout<<s.str<<endl;
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有