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 Abstract and Sealed Properties

Although specified as valid in the ECMA C++/CLI , in the Microsoft Visual C++ 2005 compiler you cannot specify the abstract (Visual C++) or sealed keywords on trivial properties, or on the property declaration of a non-trivial property.

To declare a sealed or abstract property, you must define a non-trivial property and specify the abstract or sealed keywords on the get and set accessor functions.

// properties_abstract_sealed.cpp
// compile with: /clr
ref struct A {
   int m_i;

   A() { m_i = 87; }

   // define abstract property
   property int Prop_1 {
      virtual int get() abstract;
      virtual void set(int i) abstract;

ref struct B : A {
   int m_i;

   B() { m_i = 86; }

   // implement abstract property
   property int Prop_1 {
      virtual int get() override { return m_i; }
      virtual void set(int i) override { m_i = i; }

ref struct C {
   int m_i;

   C() { m_i = 87; }

   // define sealed property
   property int Prop_2 {
      virtual int get() sealed { return m_i; }
      virtual void set(int i) sealed { m_i = i; };

int main() {
   B b1;
   // call implementation of abstract property

   C c1;
   // call sealed property
86 87

Community Additions

© 2015 Microsoft