Re: Undefined reference to...
* James Kanze, on 11.11.2010 19:34:
On Nov 11, 4:01 pm, "Alf P. Steinbach /Usenet"<alf.p.steinbach
+use...@gmail.com> wrote:
* James Kanze, on 11.11.2010 10:16:
[...]
It's not clear what you're attempting, but it may be that you
want a Meyers' singleton:
class Base
{
public:
virtual void printOut() = 0;
static Base& getLower();
};
class Extended: public Base
{
public:
void printOut() { cout<< "hello"; }
};
Base& Base::getLower()
{
static Extended e;
// Whatever code you were intending to have here, then:
return e;
}
Note that with this scheme you always get the same object --
a singleton -- from 'getLower'.
Just for the record, that's *not* a Meyers' singleton, or any
other type of singleton.
Sorry, it is a singleton, and it is a Meyers' singleton.
There are many definitions of "singleton".
I'm using the one specified by the people who invented the
pattern, the one documented in the GoF book, and the one which
served as the basis of the name.
Well, you're quibbling about terminology, not realizing that "vehicle" can mean
something more general than a Mazda RX7.
Now, I gave you some pointers, including usage in direct conflict with your POV.
You should have been able to gain an understanding from that.
If not, then sorry, can't help.
By the way, I sincerely doubt that you do know who invented singletons. I'm
treating that comment as arm-waving trying to implant the notion of you having a
very intimate knowledge of the early history of singletons. Which, even you were
an expert in the early history of singletons (a very peculiar interest, but then
so are some hobbies), would be totally irrelevant to modern usage.
Simplistic definitions (e.g., Wikipedia's article on
singletons) focus on a restriction to a single object, as you
do, since that's common usage.
And since that's what the design pattern was designed for.
What applies here is the more general concept of a globally
single object that can only be accessed via a function and
that is created on demand.
Lazy construction. A concept which goes back even before
singletons. With another name.
Sorry, no, lazy construction is involved in that meaning of singleton, but lazy
construction is a term or description that also applies to many other situations.
Cheers & hth.,
- Alf
--
blog at <url: http://alfps.wordpress.com>