Should this be a member function?

I have created many functions which I wish to use but am unsure whether they should be inserted in to the class as a member function. I am wondering if this problem is leading to the failure of the class to compile. I have written the errors which I am getting getting next to where the problem lies.

Thank you



#include <iostream>
#include <cstdlib>

using namespace std;

class badger_susceptible{

int AdMs,AdFs,JuvMs,JuvFs,CubMs,CubFs; //unqualified if before ; token
//variables need updating each step

public:
badger_susceptible(); //constructor
double Birth(B); //functions expected ; before ()
double Death(D); // " "
double Immig(Imigration);
double Emig(Emigration);
double SE() const {return StoE;} // return badger s to e// StoE undeclared first use function
double EI() const {return EtoI;}
double JuvAdult(JuvtoAdult); //functions expected ; before ()
double CubJuv(CubtoJuv); //functions expected ; before ()
~badger_susceptible(); //destructor
};




int main ()
{

badger_susceptible AdMs; expected ; before AdMs

AdMs.Birth(); // class has no member named Birth
AdMs.SE(); // " "
AdMs.EI()
AdMs.Immig();
AdMs.Emig();



system("PAUSE");
return 0;
}
Last edited on
You parameter lists are incomplete in your function declarations. Each parameter entry must specify a type and a name (the name isn't required in the declaration, but is required in the definition). You are only specifying the parameter names. ie:

double Birth(B);

What is the type of parameter B (assuming you haven't defined some type somewhere as called B). It should be something like:

double Birth(int B);

AdMs.Birth(); // class has no member named Birth This is generating an error because you haven't defined a member function Birth that takes zero parameters. You can either do this by overloading member function Birth with a declaration that takes no parameters, or define your existing member function Birth with 1 parameter that has a default value.
Either this:
1
2
double Birth(int B); 
double Birth(); 

Or this:
 
double Birth(int B = 0); 
Thank you, I was getting very confused.
I am afraid that I haven't been able to figure out where this primary expression should be. I've tried various modes.

Thank you,




#include <iostream>
#include <cstdlib>

using namespace std;

class badger_susceptible{

int& AdMs,AdFs,JuvMs,JuvFs,CubMs,CubFs; //variables need updating each step

public:
badger_susceptible(); //constructor
double Birth (float& B); //function updated with each time step
double Death (float& D); // function updated with each time step
double Immig (float& Imigration);// function updated with each time step
double Emig (float& Emigration);// function updated with each time step
double SE (float StoE) const {return StoE;} // return badger s to e, constant values
double EI (float EtoI) const {return EtoI;} // return badger s to e, constant values
double JuvAdult (float& JuvtoAdult); // function updated with each time step
double CubJuv (float& CubtoJuv); // function updated with each time step
~badger_susceptible(); //destructor
};




int main ()
{

badger_susceptible AdMs;

AdMs.Birth(float& B=2); // expected primary expression before 'float'
AdMs.SE(float& StoE=0.01); // " "
AdMs.EI(float& EtoI=0.1); // " "
AdMs.Immig(float& Immigration=0.3); // " "
AdMs.Emig(float& Emigration=0.3); // " "

system("PAUSE");
return 0;
}
Topic archived. No new replies allowed.