Here goes:
What I want to do seems simple enough, but I don''t know how exactly. Let use define the following classes for demonstrative purposes:
class One
{
public:
int x;
int doubleNumber(int a)
{
return (a * 2);
}
};
class Two
{
public:
int y;
int doubleNumberPlusOne(int b);
}
Ok. I want to be able to use the doubleNumber function in both the following ways:
int Two::doubleNumberPlusOne(int b)
{
// doubleNumber() is from class One
return (doubleNumber(b) + 1);
}
// also, I want to be able to do this:
Two t1;
int x = t1.doubleNumber(5);
Is this clear? I want a class to be able to use another class''s functions. Now I don''t mean just to do the same thing, but to actually call the function from within the class. The only way I could figure to do this is by making a function pointer in the Two class and then make it equal the function in One, but there must be a better way to do this. Is this where virtual functions come in? ...because I don''t know anything about them. Oh right, and I don''t simply want class Two to inherent class One, I just want to use one of its functions.
I hope this makes sense...
Thanks in advance,
Briar LoDeran