Meyers-Singleton

C

Chris Forone

hello group,

is there a problem with meyers-singleton when defined in header-file?

example (someheader.h):

class a
{
static a& Instance() {static a instance; return instance;}
}

or can a static member not be implicit inline?

thx & hand, chris
 
A

Alf P. Steinbach

* Chris Forone:
is there a problem with meyers-singleton when defined in header-file?
No.


example (someheader.h):

class a
{
static a& Instance() {static a instance; return instance;}
}

If the class definition was corrected by adding the required semicolon,
the Instance member function would still be inaccessible because it's
private.

If the above was not your actual code, then please read the FAQ item on
how to post a question about code that does not work.

Cheers, & hth.,

- Alf
 
C

Chris Forone

Alf said:
* Chris Forone:

If the class definition was corrected by adding the required semicolon,
the Instance member function would still be inaccessible because it's
private.
i have Instance() public, and semicolon in place...
If the above was not your actual code, then please read the FAQ item on
how to post a question about code that does not work.
no, i have written it... next time i will do it better!
Cheers, & hth.,

- Alf
thanks a lot, chris
 
J

James Kanze

is there a problem with meyers-singleton when defined in
header-file?
example (someheader.h):
class a
{
static a& Instance() {static a instance; return instance;}
}
or can a static member not be implicit inline?

There's no problem as far as the language is concerned, but it's
a good way to make maintenance intolerable and introduce
additional source code coupling.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top