Virtual Properties in MC++

R

Roy Chastain

I have tried this on a couple of occasions and each time the resulting
program goes into a loop and eventually gets a stack overflow.

public __gc BaseClass {
__property virtual int get_IntValue (void)
{ return 3; }
};

public __gc DerivedClass: public BaseClass {
__property virtual int get_IntValue (void)
{ return BaseClass::IntValue; }
};

........calling code.....

DerivedClass *loop = new DerivedClass();
loop->IntValue;

Anyone know if I am doing this wrong or if the compiler etc is broken?

Thanks
 
S

Stoyan Damov

Replace
return BaseClass::IntValue;
with
return BaseClass::get_IntValue();
or
return __super::get_IntValue();

Cheers,
Stoyan Damov
 
G

Gary Chang [MSFT]

Hi Roy,

Thanks for your post!

Thanks for your feedback. I have reproduced it and am performing research
on it. I will get back here with more information as soon as possible.


Gary Chang
Microsoft Online Partner Support
Get Secure! – www.microsoft.com/security
This posting is provided "AS IS" with no warranties,and confers no rights.
--------------------
| From: Roy Chastain <[email protected]>
| Subject: Virtual Properties in MC++
| Date: Thu, 09 Oct 2003 11:56:49 -0400
| Organization: KMSystems, Inc.
| Reply-To: (e-mail address removed)
| Message-ID: <[email protected]>
| X-Newsreader: Forte Agent 1.92/32.572
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Newsgroups: microsoft.public.dotnet.languages.vc
| NNTP-Posting-Host: 66.20.246.162
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:29243
| X-Tomcat-NG: microsoft.public.dotnet.languages.vc
|
| I have tried this on a couple of occasions and each time the resulting
| program goes into a loop and eventually gets a stack overflow.
|
| public __gc BaseClass {
| __property virtual int get_IntValue (void)
| { return 3; }
| };
|
| public __gc DerivedClass: public BaseClass {
| __property virtual int get_IntValue (void)
| { return BaseClass::IntValue; }
| };
|
| .......calling code.....
|
| DerivedClass *loop = new DerivedClass();
| loop->IntValue;
|
| Anyone know if I am doing this wrong or if the compiler etc is broken?
|
| Thanks
|
| -------------------------------------------
| Roy Chastain
| KMSystems, Inc.
|
 
R

Roy Chastain

Thanks, but should my syntax work correctly?

Replace
return BaseClass::IntValue;
with
return BaseClass::get_IntValue();
or
return __super::get_IntValue();

Cheers,
Stoyan Damov
 
R

Roy Chastain

I agree, let me rephrase my question.

Is there anything in the doc that would indicate that my syntax should
not work or that your syntax is the only one that should work?

Well, it's up to Microsoft:) It's not C++. It's Managed C++:)

Cheers,
Stoyan
 
S

Stoyan Damov

Managed Extensions for C++ Specification

13.1 Scalar Properties

Constraint
There shall be only one scalar property declared in a single
scope with the same identifier. SCALAR PROPERTIES CANNOT BE OVERLOADED.

HTH,

Stoyan

Roy Chastain said:
I agree, let me rephrase my question.

Is there anything in the doc that would indicate that my syntax should
not work or that your syntax is the only one that should work?
 
G

Gary Chang [MSFT]

Hi Roy,

Have you read Stoyen's reply? It's really the key to your question.

Since the runtime property is a new concept to Managed C++, The Managed
Extensions provide a mechanism to write and import a class that contains a
common language runtime property, you can write 2 kinds of properties:
Scalar Property and Indexed Property.

The property used in your code is Scalar Property, there shall be only one
scalar property declared in a single scope with the same identifier and the
Scalar properties cannot be overloaded. For this reason, the complier can
only recognize the "__property virtual int get_IntValue (void)" definition
of the DerivedClass in the whole app's scope and ignores the previous one
defined in the BaseClass. So when "return BaseClass::IntValue" is executed
in the
DerivedClass:__property virtual int get_IntValue (void){...}, it just call
himself recursively,
results infinite loop and call stack overflow finally.

You can find more detailed information about the Property in Managed C++:

"13 Properties"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/ht
ml/vcManagedExtensionsSpec_13.asp

"13.1 Scalar Properties"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/ht
ml/vcManagedExtensionsSpec_13_1.asp

"13.2 Indexed Properties"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/ht
ml/vcManagedExtensionsSpec_13_2.asp

Hope it helps!

Gary Chang
Microsoft Online Partner Support
Get Secure! – www.microsoft.com/security
This posting is provided "AS IS" with no warranties,and confers no rights.
--------------------
| From: Roy Chastain <[email protected]>
| Subject: Re: Virtual Properties in MC++
| Date: Fri, 10 Oct 2003 09:22:09 -0400
| Organization: KMSystems, Inc.
| Reply-To: (e-mail address removed)
| Message-ID: <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| X-Newsreader: Forte Agent 1.92/32.572
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Newsgroups: microsoft.public.dotnet.languages.vc
| NNTP-Posting-Host: 66.20.246.162
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:29275
| X-Tomcat-NG: microsoft.public.dotnet.languages.vc
|
| I agree, let me rephrase my question.
|
| Is there anything in the doc that would indicate that my syntax should
| not work or that your syntax is the only one that should work?
|
| On Fri, 10 Oct 2003 16:15:11 +0300, "Stoyan Damov" <[email protected]>
| wrote:
|
| >Well, it's up to Microsoft:) It's not C++. It's Managed C++:)
| >
| >Cheers,
| >Stoyan
| >
| >| >> Thanks, but should my syntax work correctly?
| >>
| >> On Fri, 10 Oct 2003 13:42:29 +0300, "Stoyan Damov" <[email protected]>
| >> wrote:
| >>
| >> >Replace
| >> > return BaseClass::IntValue;
| >> >with
| >> > return BaseClass::get_IntValue();
| >> >or
| >> > return __super::get_IntValue();
| >> >
| >> >Cheers,
| >> >Stoyan Damov
| >> >
| >> >| >> >> I have tried this on a couple of occasions and each time the
resulting
| >> >> program goes into a loop and eventually gets a stack overflow.
| >> >>
| >> >> public __gc BaseClass {
| >> >> __property virtual int get_IntValue (void)
| >> >> { return 3; }
| >> >> };
| >> >>
| >> >> public __gc DerivedClass: public BaseClass {
| >> >> __property virtual int get_IntValue (void)
| >> >> { return BaseClass::IntValue; }
| >> >> };
| >> >>
| >> >> .......calling code.....
| >> >>
| >> >> DerivedClass *loop = new DerivedClass();
| >> >> loop->IntValue;
| >> >>
| >> >> Anyone know if I am doing this wrong or if the compiler etc is
broken?
| >> >>
| >> >> Thanks
| >> >>
| >> >> -------------------------------------------
| >> >> Roy Chastain
| >> >> KMSystems, Inc.
| >> >
| >>
| >> -------------------------------------------
| >> Roy Chastain
| >> KMSystems, Inc.
| >
|
| -------------------------------------------
| Roy Chastain
| KMSystems, Inc.
|
 
R

Roy Chastain

Well, it is now obvious to me that I am not smart enough to read MS
documentation.

Given the words that there can only be one definition in a scope and
that they (properties) can not be overloaded, I arrived at the
conclusion that the following was not valid.

__gc class dummy:
{
__property UInt32 VariableProperty (void)
{ return 4; }
__property String * VariableProperty (void)
{ return S"Abc"; }
};

I always thought that class produced a scope therefor having the same
name in two different classes was not violating the single instance
per scope rule and that since the definitions were the same in the two
classes they were not overloaded.

Now the scope is the assembly??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top