ok,so i have 3 classes,we'll just call them a,b and c.
c is a general purpose class,so a and b both inherit c.
now,everything works fine,but the problem is,when i call a and b in main i have access to the functions in c.
in c there are many functions,of which i only want 1 to be accesible in main,through a and b,and the others not to be.
how would i do this?
i tried setting all the functions except the one to private,didn't work.
i tried setting them to protected and the one func to public,didn't work
i'm really new to this,but having the classes inherit C(general purpose)
really brings a lot of order to my code.
The other option is:
Make just one function protected public and make others private. Then make a and b friends of c.
If this option did not solve your problem, then I'm not sure what will. C++ is not like java where there is a 4th access modifier namely package which limits the scope of some fields/methods to just classes defined in the same package. You might have to reconsider your design method
//here is what it looks like in the code
//generalPurpose.h
class GeneralPurpose
{
private:
int alphabetType_;
GeneralPurpose();
virtual ~GeneralPurpose();
int Determinant2x2(int a[][2]);
int mod(int a, int b);
int gcd(int a, int b);
char toChar(int x);
int toNum(char x);
protected:
void setAlphabetType(int alphabetType);
};
//simpleciphers.h
class Simpleciphers: private GeneralPurpose
{....}
//medciphers.h
class Medciphers: private GeneralPurpose
so to inherit private functions i need to put public
thats kinda confusing
but still
when i try to call
simpleciphers.setAlphabetType();
in main
it still says protected
//generalPurpose.h
class GeneralPurpose
{
private:
int alphabetType_;
GeneralPurpose();
virtual ~GeneralPurpose();
int Determinant2x2(int a[][2]);
int mod(int a, int b);
int gcd(int a, int b);
char toChar(int x);
int toNum(char x);
public:
void setAlphabetType(int alphabetType);
friendclass Simpleciphers;
friendclass Medciphers;
};
//simpleciphers.h
class Simpleciphers: public GeneralPurpose
{....}
//medciphers.h
class Medciphers: public GeneralPurpose