Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ __declspec(property())和类声明器_C++_Visual C++_Properties_Declspec - Fatal编程技术网

C++ __declspec(property())和类声明器

C++ __declspec(property())和类声明器,c++,visual-c++,properties,declspec,C++,Visual C++,Properties,Declspec,所以我一直在尝试实现与C#中相同类型的get和set。但有些东西产生了一些疑问,这些变量是如何在C++中的引擎盖下声明的。代码如下: class foo { foo Getter() { return *this; } foo f; //this isn't allowed __declspec(property(get = Getter)) foo f2; // but this IS }; 这里发生了什么? < C++ >请为编译器添加一个标

所以我一直在尝试实现与C#中相同类型的get和set。但有些东西产生了一些疑问,这些变量是如何在C++中的引擎盖下声明的。代码如下:

class foo {
    foo Getter() {
        return *this;
    }
    foo f; //this isn't allowed
    __declspec(property(get = Getter)) foo f2; // but this IS
};

<>这里发生了什么?

< C++ >请为编译器添加一个标记(我猜
visualc++
)。C++没有属性。<代码> fof;<代码>声明无效,因为此时
foo
不是完整的类型。你不能让一个类型成为它自己的成员(但你可以让一个指针或引用作为它自己的成员)。我明白你的意思。但是,
\uu declspec(property())
具体做了什么来允许在这里声明一个不完整的类型呢?是的,它是visual c++(忘记添加标记,现在添加)
f2
只是语法上的糖衣盖过了
Getter()
,所以没有实际的
Foo
成员。因此,不完整的声明足以使其有效。