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

C++\CLI static const System::String^ not supported?

I'm converting MC++ to C++/CLI and for some reason it's not cool with

static const System::String^

How am I supposed to have static constant strings then?

Feb 13 '07 #1
6 15598
On Feb 13, 2:47 pm, "DaTurk" <mmagd...@hotmail.comwrote:
I'm converting MC++ to C++/CLI and for some reason it's not cool with

static const System::String^

How am I supposed to have static constant strings then?
That's weird. Perhaps you can post more code. From what I
understand, String is in fact immutable, and if you intend to mutate a
lot of strings use the more efficient StringBuilder class.

For String don't forget to always instantiate with gcnew or String
^AStr = "Some Text";

RL

Feb 14 '07 #2
On Feb 13, 7:43 pm, "raylopez99" <raylope...@yahoo.comwrote:
On Feb 13, 2:47 pm, "DaTurk" <mmagd...@hotmail.comwrote:
I'm converting MC++ to C++/CLI and for some reason it's not cool with
static const System::String^
How am I supposed to have static constant strings then?

That's weird. Perhaps you can post more code. From what I
understand, String is in fact immutable, and if you intend to mutate a
lot of strings use the more efficient StringBuilder class.

For String don't forget to always instantiate with gcnew or String
^AStr = "Some Text";

RL
THis is a snippet out of the CLI header file

// P U B L I C
public:
//Constants
static const int test = 1;
static const System::String^ KEY_USERNAME = "UserName";

and the error I get is, well the warning is

warning C4400: 'const System::String ^' : const/volatile qualifiers on
this type are not supported

it's a const, so I'm not newing it myself, I'm assigning it a string
literal;

Feb 14 '07 #3
I'm converting MC++ to C++/CLI and for some reason it's not cool with

static const System::String^

How am I supposed to have static constant strings then?
Please see "literal" keyword to resolve the issue.
--
Vladimir Nesterovsky
Feb 14 '07 #4

"DaTurk" <mm******@hotmail.coma écrit dans le message de news:
11**********************@h3g2000cwc.googlegroups.c om...
I'm converting MC++ to C++/CLI and for some reason it's not cool with

static const System::String^

How am I supposed to have static constant strings then?
"static const" cannot bu used in C++/CLI. You must use "literal" isntead. I
am not sure to understand why MS introduced this new keyword ("literal"
produces some special meta-data in the class type descriptor in MSIL, but I
fail to see why they couldn't use "static const" to the same effect).

The details are explained here but I fail to see the reason for this change
: http://msdn2.microsoft.com/en-gb/lib...01(vs.80).aspx

Arnaud
MVP - VC
Feb 14 '07 #5
You have two alternatives:
1. static System::String ^ const foo = "a";
2. literal System::String ^foo = "a";

Note that the first alternative, minus the 'static', is the only way to
declare method-level string constants in C++/CLI.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
"DaTurk" wrote:
I'm converting MC++ to C++/CLI and for some reason it's not cool with

static const System::String^

How am I supposed to have static constant strings then?

Feb 19 '07 #6

"David Anton" <Da********@discussions.microsoft.comwrote in message
news:B1**********************************@microsof t.com...
You have two alternatives:
1. static System::String ^ const foo = "a";
2. literal System::String ^foo = "a";

Note that the first alternative, minus the 'static', is the only way to
declare method-level string constants in C++/CLI.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
"DaTurk" wrote:
>I'm converting MC++ to C++/CLI and for some reason it's not cool with

static const System::String^

How am I supposed to have static constant strings then?

That would be a handle to a constant String. .NET does not have a concept
of a syntactically immutable object, only by semantics of the implementation
are objects immutable (and Strings are pretty much immutable without needed
to specify const). What you want is a name that always refers to the same
String objects, that's a constant handle. Dave pointed out that you would
write that as "String^ const". That's still not compile-time constant, the
value must be loaded out of the declaring assembly at JIT time. Only the
literal keyword gives you true compile-time constness.
Feb 19 '07 #7

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

Similar topics

3
by: Jan13 | last post by:
Hi, I'm new to programming in C++ (using VC6) and ran into the following problem: I want to declare and define a class member variable as 'static const', but something seems to go wrong with...
3
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...
3
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. ...
4
by: cppsks | last post by:
"Defining static const variables inside the class is not universally supported yet, so for now I guess you'll have to move the definition out of the body of the class. No, static const inside...
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>
10
by: Dave | last post by:
const static int ARRAY_SIZE = 4; Comeau online gives this warning: "ComeauTest.c", line 10: warning: storage class is not first const static int ARRAY_SIZE = 4; Why is static const...
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: John Goche | last post by:
Hello, I would like to know whethere there is a difference between a const variable and a static const variable inside a class. After all, if a variable is const in a class, the compiler can...
7
by: Spoon | last post by:
Hello everyone, I have a Packet class I use to send packets over the Internet. All the packets sent in a session are supposed to share a common random ID. I figured I'd use a static const...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.