473,881 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class A{static const int b = 1; };

I read in "Thinking in C++" this code works:
---------
class A
{
static const int b = 1;
};
---------
but it doesn't!
I do something wrong?
I use VC++6 and it returns:
-------
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'b' : pure specifier can only be specified for functions
-------
Jul 19 '05
14 4491
"<- Chameleon ->" <ch******@hotma il.NOSPAM.com> wrote in message news:<bk******* **@nic.grnet.gr >...
I read in "Thinking in C++" this code works:
---------
class A
{
static const int b = 1;
};
---------
but it doesn't!
<http://www.comeaucompu ting.com/tryitout/> compiles it just fine. If
you're going to use a compiler as a measure of code correctness, use
that one. :)
I do something wrong?
I use VC++6 and it returns:
-------
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'b' : pure specifier can only be specified for functions
-------


VC++6 is wrong. VC++.NET compiles it.

In the short term, maybe try this instead:

class A { enum { b = 1 }; };

Or, if you don't need it as a compile-time constant (e.g., for use as
a template parameter, size of an array, etc.), initialize it when you
define it in a .cpp file:

// A.h
class A {
static const int b;
};

// A.cpp
const int A::b = 1;

- Shane
Jul 19 '05 #11
"WW" <wo***@freemail .hu> wrote...
Victor Bazarov wrote:
"WW" <wo***@freemail .hu> wrote...
[...]
I assume Alexander meant [...]


He didn't mean anything. He can't mean anything.
He has no device with which to mean.


I see. He has no device with which to mean. So he cannot be mean. ;-)


Nah. It's actually simpler. He cannot be. Unless you let him,
by replying to his nonsense. Two more times and you (and others
feeding that idiot troll) will probably join him in my killfile.
You don't have to care about that. I'm just pondering.
Jul 19 '05 #12
WW
Victor Bazarov wrote:

Nah. It's actually simpler. He cannot be. Unless you let him,
by replying to his nonsense. Two more times and you (and others
feeding that idiot troll) will probably join him in my killfile.
You don't have to care about that. I'm just pondering.


If you killfile me I cannot send you my C++ language proposal for review.
It would be shame. How do you expect *me* to get it right? Drop me a mail
if you think you would have time and want to look at something like that.

BTW I was not trying to feed any troll, I was trying to keep the tension
down. Well, remind me time to time to not seek for a carrier in marriage
concunciling. :-(

--
WW aka Attila
Jul 19 '05 #13
WW
WW wrote:
[SNIP]
tension down. Well, remind me time to time to not seek for a carrier
in marriage concunciling. :-(


And to not to teach spelling..

--
WW aka Attila
Jul 19 '05 #14

Victor Bazarov wrote:

"WW" <wo***@freemail .hu> wrote...
Victor Bazarov wrote:
"WW" <wo***@freemail .hu> wrote...
> [...]
> I assume Alexander meant [...]

He didn't mean anything. He can't mean anything.
He has no device with which to mean.
I see. He has no device with which to mean. So he cannot be mean. ;-)


Nah. It's actually simpler. He cannot be. Unless you let him,
by replying to his nonsense. Two more times and you (and others
feeding that idiot troll) will probably join him in my killfile.


Aha. How scary.
You don't have to care about that. I'm just pondering.


Medication, Bazarov. Take a dose of anti-hysteria pills.

regards,
alexander.
Jul 19 '05 #15

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

Similar topics

3
3622
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...
3
2241
by: Steven T. Hatton | last post by:
Sorry about the big code dump. I tried to get it down to the minimum required to demonstrate the problem. Although this is all done with GNU, I believe the problem I'm having may be more general. Someone on the SuSE programming mailing list suggested my problem is that I'm trying to execute a function (I assume he meant the constructor) at compile time. The same source code compile if I don't try to split it up into separate libraries. ...
2
3793
by: Jonas Cord | last post by:
Hi, I'm trying to learn proxy classes in C++ so I've written the following code, trying to modify an example given in Deitel & Deitel's C++ book. I am trying to "hide" details of the original class (employee.h) through a proxy class (employeeproxy.h). What am I doing wrong? Please help... I will be grateful forever. employee.h ----------
10
3495
by: Not Available | last post by:
On the host server: namespace JCart.Common public class JCartConfiguration : IConfigurationSectionHandler private static String dbConnectionString; public static String ConnectionString { get { return dbConnectionString;
5
3614
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles fine. 1 / Now If I move the getSpectrumAtDistance( const T &dist ) method definition in SpectralProfofile.cc let's say the compiler says core/profile.cc:199: error: `kNumBins' was not declared in this scope
14
2123
by: Gary Wessle | last post by:
Hi how can I initialize a const char* myarr in a class constructor? class Myclass { const char* myarr = { "abc", "def" }; .... };
8
1735
by: Bern McCarty | last post by:
I have a simple ref class in its own namespace that needs to coexist with a legacy typedef alias for "unsigned int" in the global namespace that has the identifier as itself. Everything compiles fine with the old MEC++ syntax, but I cannot figure out how to write the code so that it will compile in C++/CLI. Can someone tell me how? Here is the code in both syntaxes: // This MEC++ code compiles just fine with VC8 using cl -c...
25
2163
by: David Sanders | last post by:
Hi, As part of a simulation program, I have several different model classes, ModelAA, ModelBB, etc., which are all derived from the class BasicModel by inheritance. model to use, for example if the parameter model_name is "aa", then choose ModelAA. Currently I do this as follows:
8
8941
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
5
2579
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so: const char *s = string_mapper<thetype>(); However I do not know the string to be associated with the type at compile time, and will need a way to set up the mapping, to be created at run time, possibly like so: void foo(char*...
0
11095
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10716
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10399
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
9552
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...
1
7952
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7108
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();...
1
4597
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
4194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3223
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.