Hi i am having problems storing default instances of a class in a vector, when i use no default constructor everything go fine.
this is the class structure:
#ifndef NEURO_H
#define NEURO_H
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
class neurona
{
private:
double v_r; //potencial de reposo
double v_u; //potencial umbral
double v_d; //potencial alcanzado al disparar
public:
neurona(double=-65.,double=-55.,double=35.) ;
~neurona() ;
neurona(const neurona &) ;
neurona & operator = (const neurona &);
};
neurona::neurona(double r,double u,double d):v_r(r),v_u(u),v_d(d)
{}
neurona::~neurona()
{}
neurona::neurona(const neurona &z)
{
v_r=z.v_r;
v_u=z.v_u;
v_d=z.v_d;
}
neurona & neurona::operator = (const neurona & z)
{
if(this!=&z)
{
v_r=z.v_r;
v_u=z.v_u;
v_d=z.v_d;
}
return *this;
}
#endif
and this is the main
int main()
{
neurona n1() ;
neurona n2(3.,3.,3.) ;
neurona n3=n2 ;
vector<neurona> v_neu(3) ;
v_neu.push_back(n1);
//v_neu[0]=n1;
//v_neu[1]=neurona2;
//v_neu[2]=neurona3;
cout<<"okidoki"<<endl;
}
i get the following error
neurona.cc: In function ‘int main()’: neurona.cc:15:11: error: no match for ‘operator=’ (operand types are ‘__gnu_cxx::__alloc_traits >::value_type {aka neurona}’ and ‘neurona()’) v_neu[0]=n1; In file included from neurona.cc:1:0: neurona.h:41:11: note: candidate: neurona& neurona::operator=(const neurona&) neurona & neurona::operator = (const neurona & z) ^~~~~~~ neurona.h:41:11: note: candidate: neurona& neurona::operator=(const neurona&) neurona & neurona::operator = (const neurona & z) ^~~~~~~
if instead of using n1 in the push_back() use n2 everything works fine, the same with n3.