Introductory note . I voluntarily chose a wide subject. You know what the quote is about studying the cat to fish, what is it. I do not need an answer to my question, I need explanations and advice. I know that you guys are good at this;)
Hi guys,
I am currently implementing some algorithms in an existing program. In short, I created a new "Adder" class. Adder is a member of another class representing a physical object that actually does a calculus, which calls adder.calc () with its parameters (just a list of objects to perform mathematical calculations).
To do this math, I need some parameters that do not exist outside the class (but can be set, see below). They are neither configuration parameters nor members of other classes. These parameters are D1 and D2, distances and three arrays of fixed size: alpha, beta, delta.
I know that some of you are more comfortable reading code than reading text, so here you are:
class Adder
{
public:
Adder();
virtual Adder::~Adder();
void set( float d1, float d2 );
void set( float d1, float d2, int alpha[N_MAX], int beta[N_MAX], int delta[N_MAX] );
float calc( List& ... );
inline float get_d1() { return d1_ ;};
inline float get_d2() { return d2_ ;};
private:
float d1_;
float d2_;
int alpha_[N_MAX];
int beta_[N_MAX];
int delta_[N_MAX];
};
Since this object is used as a member of another class, it is declared in * .h format:
private:
Adder adder_;
Thus, I could not initialize the arrays (alpha / beta / delta) directly in the constructor (int T [3] = {1, 2, 3};), without the need to iterate over all three arrays, I was thinking about placing them into a static constant, but I don’t think the right way to solve such problems.
,
Adder::Adder()
{
int alpha[N_MAX] = { 0, -60, -120, 180, 120, 60 };
int beta[N_MAX] = { 0, 0, 0, 0, 0, 0 };
int delta[N_MAX] = { 0, 0, 180, 180, 180, 0 };
set( 2.5, 0, alpha, beta, delta );
}
void Adder::set( float d1, float d2 ) {
if (d1 > 0)
d1_ = d1;
if (d2 > 0)
d2_ = d2;
}
void Adder::set( float d1, float d2, int alpha[N_MAX], int beta[N_MAX], int delta[N_MAX] ) {
set( d1, d2 );
for (int i = 0; i < N_MAX; ++i) {
alpha_[i] = alpha[i];
beta_[i] = beta[i];
delta_[i] = delta[i];
}
}
: - init() - ? ?
: ?