Re: Need a way for forgetful developers

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



For a similar case of derived classes (not encapsulated objects) I think following could work quite well: the helper object HiddenValue which can be created only in the Base class, all other classes need to use Func to create it. If you need to return some return value from the function it may get more complicated, but you should always be able to solve this with an additional argument.

I am not sure if you will be able to adapt this to inner objects, though.

(Sidenote: To me a surprise was that if I wanted the ForceBase Func(){} variant to trigger an error, I had to use the function. Without the main it did not fail. I guess something to do with how VC instantiates inlined functions)

Ondrej
-----------

class Base
{
public:
class ForceBase
{
friend Base;

private:
ForceBase(){}
};

ForceBase Func()
{
return ForceBase();
}
};

class Derived: public Base
{
public:
//ForceBase Func() {return ForceBase();} // error
//ForceBase Func(){} // error
ForceBase Func() {return Base::Func();} // OK
};

int main(int argc, const char * argv[])
{
Derived a;
a.Func();
return 0;
}



Kürţat napsal(a):
"initialize" method can be called at any time, not just construction phase. The name "initialize" recalls constructors so it may be better to name it as "reset" :)

"Vladimir Grigoriev" <vlad.moscow@xxxxxxx> wrote in message news:emL$33ctIHA.552@xxxxxxxxxxxxxxxxxxxxxxx
Include an initializing method into the constructor of your inner object.

Vladimir Grigoriev

"Kürţat" <xx@xxxxxx> wrote in message news:et5XtxctIHA.2064@xxxxxxxxxxxxxxxxxxxxxxx
Hi All,

I may be in search of impossibility but I thing this is worth asking :

Almost every developers define classes and use them in anothers. If A is a class and B uses A then we can name B as outer class and A as inner class.

We will make some assumptons at this time :
- Outer class and inner class both has a method named initialize,
- Outer class can define many inner class objects,
- In its initialize method, outer class should call the initialize method of every inner class objects,

It is highly possible to define an inner class object but forget to call its initialize method in the outer object's initialize method. I need a compile time (some runtime solutions already at hand)coupling mechanism to warn developer about missing method calls. Do you have any idea?

(I am using Visual Studio Team System 2008 Development Edition.)

Thanks in advance





.



Relevant Pages

  • Need a way for forgetful developers
    ... Almost every developers define classes and use them in anothers. ... class and B uses A then we can name B as outer class and A as inner class. ... In its initialize method, outer class should call the initialize method of ...
    (microsoft.public.vc.language)
  • Re: Need a way for forgetful developers
    ... class and B uses A then we can name B as outer class and A as inner class. ... Outer class can define many inner class objects, ... In its initialize method, outer class should call the initialize method ...
    (microsoft.public.vc.language)
  • Re: Trying to create a working internal confirm JOptionPane
    ... inner class, because it is an inner class, belongs to an object of the outer ... That means there is an outer class "this", ... It is not a static variable reference, but a completely different part of the Java language. ... Your mistake was thinking that one part of the Java language should follow rules from another part. ...
    (comp.lang.java.help)
  • Re: Updating GUI & Running Program (AND accessing common variables!)
    ... >> outer class from the inner class, I get a compile error that says I can't ... > You need to clarify what you mean by 'in the outer class'. ... > make a long story short, an anonymous inner class can only access local ... Okay, let me rephrase, to make sure I understand this correctly. ...
    (comp.lang.java.gui)
  • Re: Want - but cannot get - a nested class to inherit from outer class
    ... dict dictA: ...   dict membB: ... AM DEFINING METHODS on the inner class. ... proceed with the outer class being the inner class' parent. ...
    (comp.lang.python)