bobsled posted:
For class A to reuse functionality of a class B, A could either
contains B or inherits from B. When should pick which?
In a book the author says that "Don't inherit from a concrete
class." Does this mean that for a concrete class B, using composition is
the only choice?
Thank you for your comments!
I've come across something like this before.
I wanted to have 2 completely independant classes, let's say called
KA and KB. Like so:
class KA
{
};
class KB
{
};
I wanted to give both of the classes access to a certain function,
let's say a function that turns generates a string out of a number.
But the string is going to be in the Thai number system. But the
thing is, I don't want anyone else do be able to touch this certain
function, therefore, I want it to be private. The following would be
ideal:
class KA
{
public:
unsigned long numbr;
private:
wchar_t szBuffer[30];
void GenerateThaiString(void);
};
class KB
{
public:
unsigned long numbr;
private:
wchar_t szBuffer[30];
void GenerateThaiString(void);
};
KA::GenerateThaiString AND KB::GenerateThaiString
{
//blah blah
return &szBuffer[12];
}
//See how I want to use the same definition for both! Anyone got any
suggestions. Again, I remind you that I want this function to be
strictly private and only accessible by the member functions of the
classes KA and KB.
Thanks in advance.
-JKop