Static access to ICore

Andreas Pakulat apaku at gmx.de
Fri Nov 16 18:35:06 UTC 2007


On 16.11.07 19:17:39, Esben Mose Hansen wrote:
> On Friday 16 November 2007 14:23:42 Kris Wong wrote:
> 
> > class Icore
> > {
> >    ICore() {
> >       instance = this;
> >    }
> >    ~ICore() {
> >       instance = 0;
> >    }
> >    ICore* self() {
> >       return instance;
> >    }
> >    static ICore* instance;
> > }
> 
> While I realize that I know next to nothing about the KDevelop project, that 
> code looks excessively dangerous  to me. At the very least, I would add a 
> check in ICore() constructor that instance is null, and likewith in the 
> destructor (that instance != 0).

Huh? Ok, the constructor check would help if one could directly create
an ICore object, but the destructor check doesn't help with anything, if
instance != it gets set to 0, if it already is 0, well nothing happens
in the end.

> I would further suggest that ICore 
> constructor/destructor is private but friends with the few classes that 
> actually need it. 

There's no way to create an ICore object, because its an abstract class.
The I in ICore stands for "Interface" ;)

Oh and the subclass "Core" of ICore that does have a constructor can
only be created by linking to a special KDevelop library, which is only
allowed to happen from the main program (i.e. there's 1 call to Core()
in main())

Andreas

-- 
You will have a long and boring life.




More information about the KDevelop-devel mailing list