【问题标题】:How do you define non-inline properties in C++/CLI如何在 C++/CLI 中定义非内联属性
【发布时间】:2012-10-20 08:51:39
【问题描述】:

在 C++/CLI according to the documentation 中,您可以这样定义属性:

public ref class Vector sealed { 
public:
   property double x {
      double get() {
         return _x;
      }

      void set( double newx ) {
         _x = newx;
      }
   } // Note: no semi-colon
};

但是,如果您只是像这样对属性进行原型制作:

public ref class Vector sealed { 
public:
   property double x {
      double get() ;
      void set( double newx );
   } // Note: no semi-colon
};

您将如何为这些原型创建实现?

【问题讨论】:

    标签: visual-c++ c++-cli


    【解决方案1】:

    为了实现给定的属性 x,您需要以下 2 个函数:

    double Vector::x::get() {
        return _x;
    }
    
    void Vector::x::set(double newx) {
        _x = newx;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-07-02
      • 1970-01-01
      • 2011-04-20
      • 2011-03-27
      • 2016-05-24
      • 1970-01-01
      • 2010-10-13
      • 1970-01-01
      • 2014-09-23
      相关资源
      最近更新 更多