If I try to do this:
class Particle {
protected:
double redshift_;
};
class Nucleus: public Particle {
Nucleus(double z): redshift_(z) {}
};
I get a compiler error saying class ‘Nucleus’ does not have any field named ‘redshift_’
, but if I do this instead:
class Nucleus: public Particle {
Nucleus(double z) { redshift_ = z; }
};
it works. Why is this?
Sorry for the (probably) dumb question -- it's the first time I try to write a derived class in C++.