How to: Declare and Use Virtual Properties
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. ArchiveDisclaimer

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
© 2015 Microsoft