473,799 Members | 2,837 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::noncopy able, in
fact).

class non_copyable : private boost::noncopya ble { /* ... */ };

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_copyab le 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 2161
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::noncopy able, in
fact).

class non_copyable : private boost::noncopya ble { /* ... */ };

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_copyab le 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_copyab le 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::noncopy able, in
fact).

class non_copyable : private boost::noncopya ble { /* ... */ };

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_copyab le 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 misunderstandin g.

V
Jul 23 '05 #7

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

Similar topics

3
3615
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 non-standard C++ or if the problem lies elsewhere. To summarize static const class members are not being accessed properly when accessed from a DLL by another external object file (not within the DLL). It only occurs when the static const...
8
8933
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. Like, for instance the Objective-C method: +(void)initialize Which has the following characteristics: It is guaranteed to be run
9
8903
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 *defined* "x"'s value to be 10, isn't above statement a
5
5622
by: desktop | last post by:
Why is this struct illegal: #include<iostream> struct debug { std::string d1 = "bob\n"; }; I get this error:
15
7873
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
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10225
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.