samedi 27 mai 2017

Are there possible troubles to use default copy constructor in clone idiom?

I have :

class myClass : public baseClass
{
public:

myClass(const unsigned short int    dim_alphabet ,const string *alf ,const map<vector<string>, int> &samples );
myClass(const approximateOracle& apOracle); //copy constructor
virtual ~myCLass();
virtual myClass* clone() const;
virtual bool    myMethod(vector<SYMBOL> str);
virtual bool    myMethod2(dfa* dfahp , vector<SYMBOL>* witness_results=NULL);




private:

void encode_data(vector< pair<vector<double> , labelType> > &mapped_samples , const map<vector<string>, int> &samples);
int length_longer_sentence;
vector<double> mean;
vector<double> standard_deviation; //data structure for save the standard_deviation of features

where implementation of clone() is:

myClass* myClass::clone() const
{
return(new myClass(*this)); //this code cause the call of copy constructor
}

I'm using the clone idiom. I would delete the explicit definition of the copy constructor. I haven't pointers that require deep copy. Thus, with the default copy constructor provided from compiler (if I delete the mine) the automatic shallow copy of members of myClass should be ok.

But I have some doubt because of the presence of the clone idiom. Is there any contraindication about delete the explicit copy constructor?

Aucun commentaire:

Enregistrer un commentaire