I have a header file like this
#ifndef __coulomb_h_
#define __coulomb_h_
#include "nml_dcvector.h"
#include <fstream>
#include <iostream>
#include <complex>
#include <vector>
using namespace std;
class Coulomb{
public:
typedef complex<double> Complex_t;
Coulomb(int na, int g1, int g2, int o)
: numAtoms(na), g_min(g1), g_max(g2), o_max(o)
{
o_total=o_max*o_max;
_H_coul = new complex<double>[1];
_H_exch = new complex<double>[1];
}
private:
complex<double>* _H_coul;
complex<double>* _H_exch;
Then in my .cpp file I write this line
Coulomb nishat = Coulomb (int a, int b, int c, int d)
which is giving segmentation fault. I guess it is due to rule of three . Then I have added this part;copy constructor and assignment constructor
Coulomb (const Coulomb& v):numAtoms(v.numAtoms), g_min(v.g_min),
g_max(v.g_max), o_max(v.o_max)
{
o_total= v.o_total;
_H_coul = new complex<double>[1];
_H_exch = new complex<double>[1];
}
Coulomb& operator= (const Coulomb& v)
{
int o_total= v.o_total;
complex<double>* _H_coul_temp = new complex<double>[1];
std::copy(v._H_coul,v._H_coul+1, _H_coul_temp ) ;
complex<double>* _H_exch_temp = new complex<double>[1];
std::copy(v._H_exch,v._H_exch+1, _H_exch_temp );
delete [] _H_coul; delete [] _H_exch;
_H_coul= _H_coul_temp;
_H_exch= _H_exch_temp;
return *this;
}
Still not working. Please anybody help me to resolve this problem. thanks
Aucun commentaire:
Enregistrer un commentaire