I'm learning c ++ concretely the 2011 standard but I can use any standard from this, my problem is that when I call car () inside the second constructor it returns the data pointer without initializing.
How can I fix it and why does this happen?
#include <iostream>
class coche
{
private:
const int num_datos = 3;
int *datos;
public:
coche()
{
datos = new int[num_datos];
}
coche(const coche &nuevo)
{
coche(); // aqui esta mi problema
std::copy(nuevo.datos, nuevo.datos + num_datos, datos);
}
~coche()
{
delete[] datos;
}
};
int main()
{
coche nuevo_coche;
coche *copia_coche = new coche(nuevo_coche);
delete copia_coche;
return 0;
}