Re: Need a way for forgetful developers
- From: Ondrej Spanel <OndrejSpanel.news@xxxxxxxxxxxxx>
- Date: Thu, 15 May 2008 21:50:01 +0200
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@xxxxxxxxxxxxxxxxxxxxxxxInclude an initializing method into the constructor of your inner object.
Vladimir Grigoriev
"Kürţat" <xx@xxxxxx> wrote in message news:et5XtxctIHA.2064@xxxxxxxxxxxxxxxxxxxxxxxHi 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
- Follow-Ups:
- Re: Need a way for forgetful developers
- From: Vladimir Grigoriev
- Re: Need a way for forgetful developers
- References:
- Need a way for forgetful developers
- From: Kürşat
- Re: Need a way for forgetful developers
- From: Vladimir Grigoriev
- Re: Need a way for forgetful developers
- From: Kürşat
- Need a way for forgetful developers
- Prev by Date: Re: Get all open windows in Taskbar at Desktop
- Next by Date: What does cl's /FD option do?
- Previous by thread: Re: Need a way for forgetful developers
- Next by thread: Re: Need a way for forgetful developers
- Index(es):
Relevant Pages
|