Static member initialization

S

shendaras

Hello,

I have a quick question about the syntax I should use to initialize a
static member variable which is non-copyable (boost::noncopyable, in
fact).

class non_copyable : private boost::noncopyable { /* ... */ };

class xyxxy { /* ... */
static non_copyable foo;
};

/* ... */

non_copyable xyxxy::foo; /* looks like a declaration to me */
non_copyable xyxxy::foo = non_copyable(); /* no copies allowed */
non_copyable xyxxy::foo(non_copyable()); /* function declaration */
non_copyable xyxxy::foo((non_copyable())); /* nope, doesn't work either
*/


I've been using "non_copyable xyxxy::foo;" but this looks wrong to me.
What's the appropriate way to initialize foo, as per the above
pseudo-code?

Thanks!
 
V

Victor Bazarov

shendaras said:

Is that you again?
I have a quick question about the syntax I should use to initialize a
static member variable which is non-copyable (boost::noncopyable, in
fact).

class non_copyable : private boost::noncopyable { /* ... */ };

class xyxxy { /* ... */
static non_copyable foo;
};

/* ... */

non_copyable xyxxy::foo; /* looks like a declaration to me */

It is a declaration. And a definition.
non_copyable xyxxy::foo = non_copyable(); /* no copies allowed */
non_copyable xyxxy::foo(non_copyable()); /* function declaration */
non_copyable xyxxy::foo((non_copyable())); /* nope, doesn't work
either */

All correct, none should work except the first one.
I've been using "non_copyable xyxxy::foo;" but this looks wrong to me.

Well, I don't know what to tell you. It's not wrong.
What's the appropriate way to initialize foo, as per the above
pseudo-code?

You've done it in the first form.

V
 
S

shendaras

Victor said:
Is that you again?

Me again? I'm not sure what you mean? Do I know you from somewhere?

[snip]
non_copyable xyxxy::foo; /* looks like a declaration to me */

It is a declaration. And a definition.
[snip]
I've been using "non_copyable xyxxy::foo;" but this looks wrong to me.

Well, I don't know what to tell you. It's not wrong.

Okay. I just wanted to make sure I wasn't simply redeclaring.

Thanks
 
J

Jaspreet

shendaras said:
Hello,

I have a quick question about the syntax I should use to initialize a
static member variable which is non-copyable (boost::noncopyable, in
fact).

class non_copyable : private boost::noncopyable { /* ... */ };

class xyxxy { /* ... */
static non_copyable foo;
};

/* ... */

non_copyable xyxxy::foo; /* looks like a declaration to me */
non_copyable xyxxy::foo = non_copyable(); /* no copies allowed */
non_copyable xyxxy::foo(non_copyable()); /* function declaration */
non_copyable xyxxy::foo((non_copyable())); /* nope, doesn't work either
*/

The first one seems perfectly fine. Why do you have doubts on this ?
 
V

Victor Bazarov

shendaras said:
Me again? I'm not sure what you mean? Do I know you from somewhere?

Probably not. But I know you. Literally 20 minutes before the post that
started this thread, there was another post titled exactly like this one,
with the contents _very_much_ like this one, from the same originating
machine, you can verify it by looking at 'NNTP-Posting-Host'. While it is
_possible_ that it was someone else using the same machine as you and
posting on the same subject as you with the same contents as you, it is
*more likely* that it _was_ you, Daniel.

I can only say that patience is a virtue.

V
 
S

shendaras

Victor Bazarov wrote:
[snip about another post from me]
I can only say that patience is a virtue.

The previous post _I_ made (and do not deny making, as if it were a
crime) was made through a newserver I've had trouble with in the past.
When I checked other servers to see if it had been sent out and didn't
see it, I thought it best to post elsewhere than rely on it 'just
getting there'.

If I offended you by this, then I'm sorry. It wasn't my intention,
certainly, to offend you. I daresay that it appears to be easy.


Daniel
 
V

Victor Bazarov

shendaras said:
[..]
If I offended you by this, then I'm sorry. It wasn't my intention,
certainly, to offend you. I daresay that it appears to be easy.

I am sorry, I didn't want to come across as offended or even annoyed.
Not at all. I ought to have used a smiley or something. My fault.

I sometimes see posts here separated by a few minutes by somebody who
appears to be a desperate student one day before his coursework is
due; they often treat this newsgroup as if it were a chat room, expecting
an immediate reply. [Not that your post was fitting this particular
pattern.] However, if you don't see your post in which you asked exactly
same question, methinks it's a good habit to excuse yourself for possible
duplication due to some server malfunction. It just might serve as a good
flame-avoidance move. I only hope you will kindly use that technique in
the future to prevent misunderstanding.

V
 

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,183
Messages
2,570,965
Members
47,512
Latest member
FinleyNick

Latest Threads

Top