Hey, I just started C++, but my book doesn't cover classes very thoroughly (yep).
I want to have a class, class_1, with two functions, F_1 and F_2, with F_1 calling F_2. I know I have to declare F_2 within F_1, but I'm not sure how to. I tried doing just "int F_1(int);" like you would usually and it didn't work, and also "int class_1.F_1(int);", and it doesn't work either. I can post the actual code or error messages if that would be helpful. Thanks
class class_1{
public:
int F_1(int,int); // you only have to define them here
int F_2(int,int);
};
int class_1::F_1(int a,int b)
{
// then you can call F_2 here, no problem.
int c = F_2(a,b);
return c;
}
int class_1::F_2(int a, int b)
{
// ...
return 0;
}
int main()
{
class class_1 object;
int number;
number=object.F_1(2,4);
return(0);
}
//int class_1::F_1(int a,int b)
//fix the declaration above too
double class_1::F_1(int a,int b)
{
//int F_2(int, int);
//this should not be here
//you have already declared
//F_2 above
//make z a double
double z;
//z=F_1(a,b);
//my guess is that you
//wanted to write:
z=F_2(a,b);
//that's why z should be
//a double and F_1 should
//return a double
z=z/2.0;
return(z);
}