Class-constant functions?
-
Hello! In C++ we could declare a function like this:
BOOL CSomeClass::SomeFunction(BOOL bSomeParameter) **const**;
The 'const' meant that the function doesn't change any member variables in the class (CSomeClass). Is there an equivalent keyword in C#? Thanks in advance and best regards, Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT) -
Hello! In C++ we could declare a function like this:
BOOL CSomeClass::SomeFunction(BOOL bSomeParameter) **const**;
The 'const' meant that the function doesn't change any member variables in the class (CSomeClass). Is there an equivalent keyword in C#? Thanks in advance and best regards, Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT)Nope - nothing on offer anything remotely like that, sorry. Christian Graus - Microsoft MVP - C++
-
Hello! In C++ we could declare a function like this:
BOOL CSomeClass::SomeFunction(BOOL bSomeParameter) **const**;
The 'const' meant that the function doesn't change any member variables in the class (CSomeClass). Is there an equivalent keyword in C#? Thanks in advance and best regards, Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT)The C# compiler does not provide support for this construct which was dubious in C++ anyway.
-
Nope - nothing on offer anything remotely like that, sorry. Christian Graus - Microsoft MVP - C++
I was thinking about the very same thing a few days back. Any idea *why* it was dropped in C# though? Somebody told me it was dropped because C# doesn't separate the declaration (.h files) from the implementation (.cpp files), but it doesn't sound very convincing. After all, I might want an abstract class' subclasses to be able to use a parameter that is passed to a virtual method, but not modify it. In fact, I found myself in that situation. I ended up re-designing the classes. I'd be grateful if you can provide a convincing answer. Cheers, Vikram.
I don't know and you don't either. Militant Agnostic
-
I was thinking about the very same thing a few days back. Any idea *why* it was dropped in C# though? Somebody told me it was dropped because C# doesn't separate the declaration (.h files) from the implementation (.cpp files), but it doesn't sound very convincing. After all, I might want an abstract class' subclasses to be able to use a parameter that is passed to a virtual method, but not modify it. In fact, I found myself in that situation. I ended up re-designing the classes. I'd be grateful if you can provide a convincing answer. Cheers, Vikram.
I don't know and you don't either. Militant Agnostic
C# contains very little const support, it's something I've been lobbying for, for some time. I think it's got to do with keeping things simple, something the C# team assure me they will continue to do, although I've presented the opinion that the language often times treats the programmer as an idiot. Christian Graus - Microsoft MVP - C++
-
C# contains very little const support, it's something I've been lobbying for, for some time. I think it's got to do with keeping things simple, something the C# team assure me they will continue to do, although I've presented the opinion that the language often times treats the programmer as an idiot. Christian Graus - Microsoft MVP - C++
Ahem, so it can't be done? No clever hacks? I'm starting to miss C++. :~ I want my class' subclasses to be unable to modify a parameter passed to a virtual method they derive from my class. Will my subclasses be free to run amok? :sigh: Cheers, Vikram.
I don't know and you don't either. Militant Agnostic
-
Ahem, so it can't be done? No clever hacks? I'm starting to miss C++. :~ I want my class' subclasses to be unable to modify a parameter passed to a virtual method they derive from my class. Will my subclasses be free to run amok? :sigh: Cheers, Vikram.
I don't know and you don't either. Militant Agnostic
The problem is that in the C# treats
const
much more "seriously" than C++. In fact a problem common in C++ code is accidently casting away somethingconst
by shifting to a reference. Look at the behavior of the keywordsealed. `sealed` can protect a lot of things from having the inheritor from overriding, modifying, etc base class behavior.
-
The problem is that in the C# treats
const
much more "seriously" than C++. In fact a problem common in C++ code is accidently casting away somethingconst
by shifting to a reference. Look at the behavior of the keywordsealed. `sealed` can protect a lot of things from having the inheritor from overriding, modifying, etc base class behavior.
Tom Larsen wrote:
The problem is that in the C# treats const much more "seriously" than C++.
I'm still new to C#, but I don't understand the basis of your statement. Could you please explain in greater detail?
Tom Larsen wrote:
sealed can protect a lot of things from having the inheritor from overriding, modifying, etc base class behavior.
Yes, but unfortunately my base method was abstract, so there's no question of sealing it. :( Cheers, Vikram.
I don't know and you don't either. Militant Agnostic