M
MaxMax
Now... I have a problem... It's an engineering problem.
I have a function, we will call it MyBigFunc. It's a function that can be
easily built as a static method, because it is the only function that the
"user" will use and it is stateless.
So I wrote something like:
class MyClass
{
public:
static int MyBigFunc() { return 0;}
};
Clearly there are some private/protected methods that are called by
MyBigFunc. There is a storage (a sub-class) that is istantiated by MyBigFunc
and is destroyed at the end of MyBigFunc. It's quite big but it's life is
short (the life of MyBigFunc) The private/protected methods receive a
pointer to this subclass.
....
private:
class MyClassSomeData
{
};
....
Then I decided to make it easily expandible, so I built some overridable
functions that are called by MyBigFunc at various times. Clearly to be
called by a static function they are static The problem is that the
"user" functions probably will need some private data that THEY will produce
(so, for example, if a1, a2 and a3 are methods called by MyBigFunc, a1 could
open a file that will be used by a2 and a3. The file must be closed in the
end). There is even the possibility (it is probable) that a derived class
will be stateful. So now I don't know what to do.
Oh... yes... I was forgetting something: at this time the base class is a
template class and it calls the methods through "template-virtual" calls
So it's more like:
template <class T>
class MyClass
{
public:
static int MyBigFunc()
{
MyClassSomeData SomeData;
T::OneFunc(&SomeData);
return 0;
}
static int OneFunc(MyClassSomeData *pSomeData) { // donothing }
};
I have a function, we will call it MyBigFunc. It's a function that can be
easily built as a static method, because it is the only function that the
"user" will use and it is stateless.
So I wrote something like:
class MyClass
{
public:
static int MyBigFunc() { return 0;}
};
Clearly there are some private/protected methods that are called by
MyBigFunc. There is a storage (a sub-class) that is istantiated by MyBigFunc
and is destroyed at the end of MyBigFunc. It's quite big but it's life is
short (the life of MyBigFunc) The private/protected methods receive a
pointer to this subclass.
....
private:
class MyClassSomeData
{
};
....
Then I decided to make it easily expandible, so I built some overridable
functions that are called by MyBigFunc at various times. Clearly to be
called by a static function they are static The problem is that the
"user" functions probably will need some private data that THEY will produce
(so, for example, if a1, a2 and a3 are methods called by MyBigFunc, a1 could
open a file that will be used by a2 and a3. The file must be closed in the
end). There is even the possibility (it is probable) that a derived class
will be stateful. So now I don't know what to do.
Oh... yes... I was forgetting something: at this time the base class is a
template class and it calls the methods through "template-virtual" calls
So it's more like:
template <class T>
class MyClass
{
public:
static int MyBigFunc()
{
MyClassSomeData SomeData;
T::OneFunc(&SomeData);
return 0;
}
static int OneFunc(MyClassSomeData *pSomeData) { // donothing }
};