我有一堂课Keywords
:
#include <boost/lambda/lambda.hpp>
class Keywords
{
public:
///Constructor
Keywords(const char*,vector<shared_ptr<RegularExpression>>,vector<string>);
Keywords(const Keywords& other);
private:
const char * xmlFile;
vector<shared_ptr<RegularExpression>> vreg;
vector<string> sw;
}
我想为const char*
和构建一个副本构造函数vector<shared_ptr<RegularExpression>>
我编码正确吗?
Keywords::Keywords(const Keywords& other):xmlFile(new char[100]),vreg(other.vreg.size())
{
strcpy((char*)xmlFile, (char*)other.xmlFile);
for (std::size_t i = 0; i < other.vreg.size(); ++i)
vreg[i] = shared_ptr<RegularExpression>(new RegularExpression(*other.vreg[i]));
}
据我了解,我复制了 Const char* 和 shared_ptr 的向量。
谢谢你。
*所以在删除 const char * 我会有*
class Keywords
{
public:
///Constructor
Keywords(string,vector<shared_ptr<RegularExpression>>,vector<string>);
Keywords(const Keywords& other);
private:
string xmlFile;
vector<shared_ptr<RegularExpression>> vreg;
vector<string> sw;
}
并且复制构造函数将是:
Keywords::Keywords(const Keywords& other):vreg(other.vreg.size()),sw(other.sw)
{
for (std::size_t i = 0; i < other.vreg.size(); ++i)
vreg[i] = shared_ptr<RegularExpression>(new RegularExpression(*other.vreg[i]));
}
解说员:
Keywords::~Keywords()
{
sw.clear();
vreg.erase(vreg.begin());
}