P
pauldepstein
I am writing a program which looks at nodes which have coordinates
which are time-dependent.
So I have a class called node which contains the private member
declarations int date; int month; (I want to consider the month as
part of the information contained in the node, as well as the date.)
The node class also contains public member function void set_month(int)
which sets the month according to the date given.
The corresponding code is void node::set_month(int given_date)
{ int calendar = given_date % 365;
if(calendar <= 31) month = 0;
etc. etc. }
I want my default constructor to assume some basic assumptions about
the node.
My plan is for the default construction node::node() to call the
set_month member function
In other words, my node::node() function would contain the line of code
set_month(date);
Is this o.k. as a line of code? In fact, would it be o.k to write
node::node()
{ set_month(date); }
Is there a problem with this with regard to either style or legality.
It seems to solve my problem but a default constructor should (I think)
be the most basic type of function and it seems wrong for a default
constructor to call on another member function.
Or is my proposed approach o.k?
Thank you,
Paul Epstein
which are time-dependent.
So I have a class called node which contains the private member
declarations int date; int month; (I want to consider the month as
part of the information contained in the node, as well as the date.)
The node class also contains public member function void set_month(int)
which sets the month according to the date given.
The corresponding code is void node::set_month(int given_date)
{ int calendar = given_date % 365;
if(calendar <= 31) month = 0;
etc. etc. }
I want my default constructor to assume some basic assumptions about
the node.
My plan is for the default construction node::node() to call the
set_month member function
In other words, my node::node() function would contain the line of code
set_month(date);
Is this o.k. as a line of code? In fact, would it be o.k to write
node::node()
{ set_month(date); }
Is there a problem with this with regard to either style or legality.
It seems to solve my problem but a default constructor should (I think)
be the most basic type of function and it seems wrong for a default
constructor to call on another member function.
Or is my proposed approach o.k?
Thank you,
Paul Epstein