为什么在密封的ref类中属性不能是公共的
Why can properties not be public inside a ref class sealed
以下代码是非法的(Visual Studio 2012 Windows Phone(创建Windows Phone direct3d应用程序))
a non-value type cannot have any public data members 'posX'
标题
ref class Placement sealed
{
public:
Placement(
float rotX,
float rotY,
float rotZ,
float posX,
float posY,
float posZ
);
float rotX, rotY, rotZ, posX, posY, posZ;
};
Cpp
Placement::Placement(
float rotX,
float rotY,
float rotZ,
float posX,
float posY,
float posZ
)
: posX( posX ),
posY( posY ),
posZ( posZ )
{
this->rotX = static_cast<float>(rotX);
this->rotY = static_cast<float>(rotY);
this->rotZ = static_cast<float>(rotZ);
}
为什么以及如何设置属性?我习惯了普通的C++而不是C++CX(我想它是这么叫的吧?)。。。我必须创建为属性服务的方法吗
*这个问题源于我最初试图创建一个普通类并创建一个指向它的指针,但却被抱怨我不能使用*,而是必须使用^,这意味着我必须创建一个ref类。。。我真的不明白为什么?*
这与WinRT或更具体地说与ARM处理器有关吗
Is是COM中的一个限制,COM是WinRT和C++/CX语言扩展的基础。COM只允许在接口声明中使用纯虚拟方法。一个属性很好,它被模拟为getter和setter方法。不是田地。
这种限制不是人为的,它强烈地去除了实现细节。当您需要支持任意语言并让它们相互对话或与API对话时,这一点非常重要。字段有一个非常糟糕的实现细节,其位置非常依赖于实现。对齐和结构打包规则对于确定该位置非常重要,并且不能保证在语言运行时之间兼容。
使用属性是一个简单的解决方法。
这是特定于WinRT和C++/CX扩展的东西。C++/CX不允许ref类包含公共字段。您需要将公共字段替换为公共属性。
ref class Placement sealed
{
public:
Placement(
float rotX,
float rotY,
float rotZ,
float posX,
float posY,
float posZ
);
property float rotX;
property float rotY;
property float rotZ;
property float posX;
property float posY;
property float posZ;
};
属性具有由编译器自动为其生成的getter和setter函数。
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么我的for循环不能正确获取argv
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 为什么我不能在 FOR LOOP 中使用 i/10,C++?
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- 为什么模板类中的对象不能返回值
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- 数组长度,为什么从命令行获取时不能使用它?
- 为什么我不能分配此QT属性
- 如何集成 c++ 和 qml.不能使用 QML 中的属性
- 为什么我不能更改结构的字符数组属性?
- 为什么在密封的ref类中属性不能是公共的
- C++输出到Windows终端使用cout<<term_cc<color,default,attrib>在Windows上正确输出颜色和属性,但在Linux上不能
- Boost属性树不能在一个文件中读取多个json数据
- 为什么c++ CLI索引属性不能在c#中工作
- 不能在 C++ 中更改另一个对象中的对象属性
- 在 C 中,除了使用 val 之外,不能更改结构属性 #define