For Programmers: Free Programming Magazines  


Home > Archive > VC Language > June 2005 > Virtual Properties









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Virtual Properties
Tamas

2005-06-10, 8:59 pm

I copy-pasted the code sample below from the MDSN Library for VS.NET 2005 beta 2:

// mcppv2_property_4.cpp
// compile with: /clr
using namespace System;
interface struct IEFace {
public:
property int VirtualProperty2 {
int get();
void set(int i);
}
};

// implement virtual events
ref class PropImpl : public IEFace {
int MyInt;
public:
property int VirtualProperty2 {
int get() {
return MyInt;
}
void set(int i) {
MyInt = i;
}
}
};

This code does not compile. It says the get and set accessors are not implemented in PrpoImpl. They obviously are. The same thing compiles without problems in beta 1. Am I missing something?


Gary Chang[MSFT]

2005-06-11, 3:59 am

Hi Tamas,

>...
>This code does not compile. It says the get and set accessors are
>not implemented in PrpoImpl. They obviously are. The same thing
>compiles without problems in beta 1. Am I missing something?


Just as the error message figured it out : the virtual function of an
Interface needs a "virtual" keyword to implement/override in its
implementing class, so add the "virtual" keyword to your implementing
function will work.
...
ref class PropImpl : public IEFace {
int MyInt;
public:
property int VirtualProperty2 {
virtual int get() {
return MyInt;
}
virtual void set(int i) {
MyInt = i;
}
}
...

So in this case, the corresponding MSDN doc is not accurate for VS2005
beta2. Since it is a pre-release documentation for Visual Studio 2005, it
will subject to change in future releases on such issues.


Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/defaul...msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com