473,408 Members | 2,009 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,408 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 4725
"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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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...
0
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...

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.