473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Static member initialization

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!

--
shendaras

Jul 23 '05 #1
6 2135
shendaras wrote:
Hello,
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
Jul 23 '05 #2
Victor Bazarov wrote:
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

Jul 23 '05 #3
shendaras wrote:
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 ?


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!

--
shendaras


Jul 23 '05 #4
shendaras wrote:
Victor Bazarov wrote:
Is that you again?

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
Jul 23 '05 #5
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

Jul 23 '05 #6
shendaras wrote:
[..]
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
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
8
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it....
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
5
by: desktop | last post by:
Why is this struct illegal: #include<iostream> struct debug { std::string d1 = "bob\n"; }; I get this error:
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.