PC Review


Reply
Thread Tools Rate Thread

const keyword on member functions

 
 
Daniel =?iso-8859-1?Q?Lidstr=F6m?=
Guest
Posts: n/a
 
      18th May 2004
Hello,

why am I not allowed to put const keyword on memberfunctions as such:

public __gc class C {
public:
int get() const;
};
?

Also, if I return a pointer to as String, do I have to add const to make it
non-changeable? For example:

public __gc class C {
public:
System::String* get() { return s; }

System::String* s;
};

What happens if I do:
C* c;
c->s = "string";
c->get() = "vector"; // can't compile it

Sorry if these are simple questions...

--
Daniel
 
Reply With Quote
 
 
 
 
Niki Estner
Guest
Posts: n/a
 
      18th May 2004
"Daniel Lidström" <(E-Mail Removed)> wrote in
news:(E-Mail Removed)...
> Hello,
>
> why am I not allowed to put const keyword on memberfunctions as such:
>
> public __gc class C {
> public:
> int get() const;
> };
> ?


Because there are no "const" functions in the CLS.
Other .net languages like C# or VB.net don't have "const" types, so they
couldn't use classes exposing functions like these.

> Also, if I return a pointer to as String, do I have to add const to make

it
> non-changeable? For example:
>
> public __gc class C {
> public:
> System::String* get() { return s; }
>
> System::String* s;
> };
>
> What happens if I do:
> C* c;
> c->s = "string";
> c->get() = "vector"; // can't compile it


System::String's are always unchangable.
If you modify a string, a new String instance will be created with the old
instance unchanged.

>
> Sorry if these are simple questions...


I'd suggest learning the .net framework with a language like C# or VB.net
instead of MC++.

Niki


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
new keyword in 'hide' base class member Man T Microsoft C# .NET 3 14th Feb 2009 12:34 AM
Can I export a const member to a COM object??? balaji.ganesan@gmail.com Microsoft C# .NET 0 21st Apr 2005 09:10 PM
use of 'new' keyword in functions Micus Microsoft C# .NET 3 24th May 2004 08:48 PM
switch a member from const to variable and viceversa Romain TAILLANDIER Microsoft Dot NET Compact Framework 2 16th Jan 2004 08:55 AM
const functions in C# ? Chris Microsoft C# .NET 20 26th Nov 2003 10:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:39 AM.