473,396 Members | 1,924 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,396 software developers and data experts.

error Message: "only const static integral data members can be initializedinside a class or struct"

Hi,

I got this error msg whilst building some classes. It is realatively asy
to fix. But I just wondered, does anyone know the technical reason why
one can't initialiaze a const static non-integral data member in a class?
Jul 23 '05 #1
2 4724
"Susan Baker" <sb****@no.spam.net> wrote in message
news:da**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com
Hi,

I got this error msg whilst building some classes. It is realatively
asy to fix. But I just wondered, does anyone know the technical
reason why one can't initialiaze a const static non-integral data
member in a class?


1. Because the C++ standard says so.
2. Because being able to do this with integral types means they can be used
where compile time constants are required, notably in specifying the size of
arrays in the class declaration. There isn't a comparable need for the
initialisation of other const static types.

--
John Carson

Jul 23 '05 #2
* Susan Baker:

I got this error msg whilst building some classes. It is realatively asy
to fix. But I just wondered, does anyone know the technical reason why
one can't initialiaze a const static non-integral data member in a class?


No. :-)

But apparently, from earlier discussions, adding support for that would
have opened a can'o'worms, other related issues to be considered.

The support that is there, for integral type constants, allows those
constants to be used as template arguments and as array size specifiers.
A double (say) constant cannot be used that way. So it seems the
committee chose to add only the minimal support absolutely required for
the most common compile time usage.

Btw., "relatively easy to fix", in the sense of finding some
work-around, isn't necessarily true, because C++ doesn't support
'inline' for constants, i.e. you cannot just use the keyword 'inline' to
make a constant definition have external linkage in a way so the that
the linker is happy with multiple definitions.

One workaround for that is to use templating, and that makes the
restriction very difficult to understand: the templating work-around
shows that it would not entail anything extra in compiler and linker
machinery to support 'inline' for this purpose.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #3

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

Similar topics

29
by: Alexander Mahr | last post by:
Dear Newsgroup, I'm somehow confused with the usage of the static keyword. I can see two function of the keyword static in conjunction with a data member of a class. 1. The data member...
3
by: Ajax Chelsea | last post by:
can not the "static const int" be replaced by "static enum" anywhere? is it necessary that define special initialization syntax for "static const int"?
2
by: heinquoi | last post by:
hello, i have the code: class window { static const HWND hWnd; static const HINSTANCE hInst; // ... next code here window (HINSTANCE ); }
9
by: Neil Kiser | last post by:
I'm trying to understand what defining a class as 'static' does for me. Here's an example, because maybe I am thinking about this all wrong: My app will allows the user to control the fonts...
1
by: geri.gan | last post by:
I have C API just like this: enum void getinfor(const struct inputinfor *a, const struct outputinfor ** b) i use p/invok to translate it to internal static extern void getinfor(ref...
1
by: rocksoft | last post by:
Hi, i got error "class not registered" when i try to create web setup and deployment project to my web application. i'm used Asp.net and c# to my application, i created web setup and deployment...
8
by: not_a_commie | last post by:
A method parameter declared as "const ref" would allow for passing large structs quickly and enforce that the struct does not get reassigned. I know there was concern before about the inability of...
6
by: .rhavin grobert | last post by:
hello;-) i frequently need the following construction: ReturnParam § Function() § { /...do something.../ someType var § = something; /...do something.../ return something;
7
by: Bill Davy | last post by:
I want to be able to write (const char*)v where v is an item of type Class::ToolTypeT where ToolTypeT is an enumeration and I've tried everything that looks sensible. There's an ugly solution, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.