Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Declare and Use Virtual Properties

This code sample shows how to declare and use virtual properties.

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

// implement virtual events
ref class PropImpl : public IEFace {
   int MyInt;
   virtual property int VirtualProperty1;

   virtual property int VirtualProperty2 {
      int get() {
         return MyInt;
      void set(int i) {
         MyInt = i;

int main() {
   PropImpl ^ MyPI = gcnew PropImpl();
   MyPI->VirtualProperty1 = 93;

   MyPI->VirtualProperty2 = 43;
93 43

Community Additions

© 2015 Microsoft