Re: C++: conditional static data member possible?
- From: loic-dev@xxxxxxx
- Date: 24 Nov 2006 00:07:23 -0800
Hola Carlos,
Here's the puzzle I'm trying to solve:
Say that I have a shared library with, among other things,
a class A of which an application may or may not
instantiate objects.
I'm trying to enforce the guarantee that by the end of the
application, at least one object of class A has executed a
given action.
That part was easy: static data member that acts like a
flag --- the given action (which is one of class A methods)
notifies that static data member to that the flag is set.
That static object is implemented through a class whose
destructor verifies that the action has taken place, and
if not, it logs an error.
Now, the real puzzle I'm facing: if the application does
not *declare* a single object of class A, I do not want to
enforce anything (i.e., I do not want to report/log an
error because no object of class A has executed the action).
Perhaps my idea is too simplistic. But why you don't just extend the
flag as follows:
- in the constructor of the static object, flag is set the
'NotInstancied'.
- in the constructor constructor of object A, flag is set to
'Instancied'.
- in the given method of class A corresponding to the action to
execute, flag is set to 'Done'
Then, in the destructor of the static object, you react depending on
the flag value:
flag==NotInstancied => do nothing
flag==Instancied => log error (action has not be called)
flag==Done => Ok.
HTH,
Loic.
.
- Follow-Ups:
- Re: C++: conditional static data member possible?
- From: Carlos Moreno
- Re: C++: conditional static data member possible?
- References:
- C++: conditional static data member possible?
- From: Carlos Moreno
- C++: conditional static data member possible?
- Prev by Date: Re: C++: conditional static data member possible?
- Next by Date: Re: Looking for a extensible shell for debug purpose
- Previous by thread: Re: C++: conditional static data member possible?
- Next by thread: Re: C++: conditional static data member possible?
- Index(es):
Relevant Pages
|