I am attempting to make a class in c++ called to store values for a number of parameters that are organized as member variables of class 'Planet' and class 'Satellite', which I want to initialize with a reference to an instance of 'Planet'. Here I provide an example where I have a 'PlanetCatalog' class with member variables 'Planet neptune' and a 'Satellite triton'.
class Planet {
public:
double a;
Planet() {}
void setParams( const double a_) {
a = a_;
}
};
class Satellite {
public:
double b;
Planet & planet;
Satellite( Planet & planet_):planet(planet_) { }
void setParams(const double b_) {
b = b_;
}
};
class PlanetCatalog {
public:
Planet neptune;
Satellite triton(neptune);
void setAll() {
neptune.setParams(1.);
triton.setParams(2.);
}
};
However, upon compiling I encounter the error.
error: unknown type name 'neptune'
Satellite triton(neptune);
Is it possible to have the Planet and Satellite stored as variables of the same class as I have done here. If not, could someone suggest a better way of organizing this functionality in c++?