Re: Registering a data class with a handler class
Hi Victor,
Thanks for your reply. I'm very new to using classes really.
class EpiCovars // Storage class
{
...
public:
// Public methods //
public:
EpiCovars();
~EpiCovars();
int init(const int, const char*, const char*);
double dist(const int&,const int&);
};
class EpiMath // The Handler class
{
private:
public:
EpiMath();
~EpiMath();
inline double beta_ij(const int&, const int&, const vector<double>&,
EpiCovars&);
Now, this seems strange. If you intend the function to be inline, you
need to provide its body. If you don't provide its body, don't try to
pretend by declaring it 'inline'. If you do provide its body here, there
is no need for the 'inline' keyword -- any function defined in the class
definition is 'inline'.
Yup, the body is defined in another file as inline double
EpiMath::beta_ij...etc. Does this mean that I don't need the 'inline'
modifier in the class definition?
class EpiMath
{
private:
EpiCovars& myData;
public:
EpiMath(const EpiCovars& dataRef) {
myData = dataRef;
}
Two points: the argument has to be a ref to non-const EpiCovars and
you need to *initialise* 'myData', not try to *assign* to it:
EpiMath(EpiCovars& dataRef) : myData(dataRef) {}
Yup, I can see that now. What I'm trying to do is to get across the
idea that once initialized, the EpiCovars object that I'm
passing-by-reference to the c-tor of EpiMath is not to be modified. Is
this the correct way to do it? I note from your later post that you
think that there are no member functions in EpiCovars that could be
called for a const object: the EpiCovars::dist(const int&,const int&)
method returns a distance (stored in the object). If it only returns
the distance, and leaves all the data unmodified, why can't it be called
for a const object?
Read up on constructors, initialiser lists, references...
I'm trying......
Thanks,
Chris