Re: C++: conditional static data member possible?



loic-dev@xxxxxxx wrote:

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:

This is exactly what I'm doing now!! The detail that this does not
solve is that I want to enforce or not the given action depending on
whether class A *appears* in the code, not depending on whether an
object of class A is actually instantiated at runtime.

That's why my example with a declaration of A inside a block scope
that never gets executed --- in that example, no object of class A
is ever instantiated, yet I wanted the condition to be enforced
(meaning, I want an error to be reported by the end of the
application).

Thanks,

Carlos
--
.



Relevant Pages

  • Re: C++: conditional static data member possible?
    ... notifies that static data member to that the flag is set. ... That static object is implemented through a class whose ... in the constructor constructor of object A, ... execute, ...
    (comp.os.linux.development.apps)
  • Re: object orientation question
    ... foo.Item2 is readOnly, then what is the appropriate method to create a foo ... that the property reads from, a constructor that takes in item2, or a shared ... > using the first constructor that the object has not just been created. ... > once" property like Item2 you check the flag and permit it to be assigned ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Virtual function call from constructor
    ... suppose this method uses overridable methods of the object. ... differently depending on whether there is or isn't a constructor ... vtable for each constructor finished or something like this -- that should also be fairly simple to implement and you do not need a "construction finished" flag, but of couse it imposes some costs. ... private, final and static methods from a constructor and only if they themselves obey this rule", right? ...
    (comp.lang.java.programmer)
  • Re: Constructor denial?
    ... can use a flag or an exception in your constructor to signal that ... > don't see why you prefer nullptr to an exception. ... > Optionally, you can set a failed flag in the constructor, and add a bool ... > for a valid reason, ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
    ... Then the individual simple GO TOs will be eliminated ... It preserves the structure of GO TO DEPENDING better ... IF FLAG = 1 THEN ... END-IF ...
    (comp.lang.cobol)