Re: Newb Question on Properties of Objects
On 2 Des, 13:51, Lionel B <m...@privacy.net> wrote:
Might look something like this:
#include <vector>
class Star
{
const int num_hours;
vector<int> bearing;
vector<int> ascension;
int brightness;
public:
// this may look silly (yes, we know there are 24 hours in a day)=
but
// it's good style not to litter your code with hard-coded consta=
nts
Non-static const data members may not be such a good idea either, see
below.
Star() : num_hours(24), bearing(num_hours), ascension(num_hours)
{
// constructor code
}
void Display(int hour) // a star "knows how to display itself"
{
// display code can access bearing[hour], etc.
}
};
[snip]
Note that the use of std::vector<Star> later in the code possibly
renders your program ill-formed, because it may cause the implicit
declaration of the implicitly defined copy assigment operator
(std::vector requires Star to be Assignable).