C++: conditional static data member possible?
- From: Carlos Moreno <moreno_at_mochima_dot_com@xxxxxxxxxxxxxx>
- Date: Thu, 23 Nov 2006 20:25:36 -0500
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).
Example:
int main()
{
B b;
b.something();
C c;
c.something();
return 0;
}
In the above code, I do not want A's static data member to
notify an error message, since class A does not appear
anywhere in the code. However, in the code below, I would
like to report the error:
int main()
{
if (some condition that is false)
{
// IOW, this code does not execute
A a;
a.the_required_action();
}
else
{
B b;
b.something();
}
return 0;
}
Notice that even though *no object of class A is instantiated*
in the above code, the mere fact that there *are* declarations
in the code for objects of class A determines that I want the
application to report the error.
Is this possible with g++ ? Ideally, everything should be
compiled to a single shared object (.so file).
Thanks,
Carlos
--
.
- Follow-Ups:
- Re: C++: conditional static data member possible?
- From: Paul Pluzhnikov
- Re: C++: conditional static data member possible?
- From: loic-dev
- Re: C++: conditional static data member possible?
- From: Richard
- Re: C++: conditional static data member possible?
- Prev by Date: Re: Looking for a extensible shell for debug purpose
- Next by Date: Re: C++: conditional static data member possible?
- Previous by thread: emacs and gtk
- Next by thread: Re: C++: conditional static data member possible?
- Index(es):