473,402 Members | 2,072 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,402 software developers and data experts.

Can you make a static constant?

Something like this:

class X
{
static const int MY_CONSTANT = 10;
}

I want the variable to be constant and to be shared by all instances
of the class so as to not waste memory.
Nov 16 '05 #1
2 994
Phill,

You should just use the const keyword then. By default, const is
static.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Phill" <wa********@yahoo.com> wrote in message
news:ac**************************@posting.google.c om...
Something like this:

class X
{
static const int MY_CONSTANT = 10;
}

I want the variable to be constant and to be shared by all instances
of the class so as to not waste memory.

Nov 16 '05 #2
Oh, excellent. I did not know that. Thank you.
Nov 16 '05 #3

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

Similar topics

14
by: Mike Hewson | last post by:
Have been researching as to why: <example 1> class ABC { static const float some_float = 3.3f; }; <end example 1>
9
by: cppsks | last post by:
Taking the address of a static const resulted in a unresolved symbol. Why is that? Is the address assigned at load time? Thanks.
2
by: Drew McCormack | last post by:
I am getting an error in g++ 4.0.0 that I did not get in g++ 3.4. I have a header with the following const variables with namespace scope: namespace Periphery { extern const double...
5
by: seans | last post by:
Hi, Is there a way to create a static variable in Javascript? I want to use a recursive function to traverse a DOM tree and examine each node. If the node is a text object I would like to save...
14
by: John Ratliff | last post by:
I'm trying to find out whether g++ has a bug or not. Wait, don't leave, it's a standard C++ question, I promise. This program will compile and link fine under mingw/g++ 3.4.2, but fails to link...
6
by: Michael B Allen | last post by:
I want to initialize a static variable to a "random" value like: static void * get_key(struct dnsreq *req) { static uint16_t next_txnid = (uint32_t)req & 0xFFFF; But gcc gives me an error: ...
8
by: raan | last post by:
Microsoft C++ apparently doesn't permit me to initialize a static constant with in my class scope. Ok, I think that is previously discussed here and people have suggested some hacks to circumvent...
3
by: Steve Folly | last post by:
Hi, I had a problem in my code recently which turned out to be the 'the "static initialization order fiasco"' problem (<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12>) The FAQ...
6
by: asit | last post by:
Static variables can't be initialized with functions, becoz these are load time processes. Why this is so ?? What is a load time process ??
8
by: aarklon | last post by:
Hi all, see:- http://linuxgazette.net/issue51/pramode.html
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.