疯狂的C ++ 11语法==> struct是什么:bar {} foo {} ;?

轨道轻赛

这在C ++ 11中可能意味着什么?

struct : bar {} foo {};
轨道轻赛

首先,我们将采用沼泽标准的抽象UDT(用户定义类型):

struct foo { virtual void f() = 0; }; // normal abstract type
foo obj;
// error: cannot declare variable 'obj' to be of abstract type 'foo'

还让我们回想一下,我们可以在定义它的同时实例化UDT:

struct foo { foo() { cout << "!"; } };          // just a definition

struct foo { foo() { cout << "!"; } } instance; // so much more
// Output: "!"

让我们结合示例,回想一下我们可以定义一个没有名称的UDT

struct { virtual void f() = 0; } instance; // unnamed abstract type
// error: cannot declare variable 'instance' to be of abstract type '<anonymous struct>'

我们不再需要有关匿名UDT的证据,因此我们可能会丢失纯虚函数。同样重命名instancefoo,我们还有:

struct {} foo;

越来越接近。


现在,如果此匿名UDT是从某个基础派生的呢?

struct bar {};       // base UDT
struct : bar {} foo; // anonymous derived UDT, and instance thereof

最后,C ++ 11引入了扩展的初始化程序,这样我们就可以使诸如此类的事情变得混乱:

int x{0};

和这个:

int x{};

最后,这是:

struct : bar {} foo {};

这是一个源自bar的未命名结构,使用空白的初始化程序实例化为foo。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

(foo,bar)= foobar()Python语法是什么意思?

在C语言中[foo] = bar是什么意思?

语法的含义是什么:<element #foo />

JavaScript语法foo:是什么意思?

.htaccess文件中“如果主机不是foo,则重定向到bar”的正确语法是什么?

这是什么C ++ C11语法:“ = {}”?

int foo = bar <<'\ n';是什么?在C ++中意味着什么?

这个语法是什么意思:const foo = () => {}

模板中的#foo =“ myFoo”语法是什么意思?

包含foo和bar的文件的Ack语法

bash中if [“ $ foo” ==“ bar”]的语法错误

“ Foobar”或“ foo”或“ bar”是什么意思?

Rust中的Foo(bar)= zar是什么?

foo = bar programname是什么意思

方法调用语法`foo.method()`和UFCS`Foo :: method(&foo)`有什么区别?

为什么foo = bar与foo = bar不同?

在C ++ 11中使用auto foo =“ bar” vs std :: string

指针分配“ * foo ++ = * bar ++;”在C中做什么?

什么是`int foo :: * bar :: *`?

C ++中的“ int&foo()”是什么意思?

“预期的struct Foo,找到了另一个struct Foo”是什么意思?

Kotlin语法混淆:有趣的Foo.bar()=(...)

这是什么疯狂?

双括号“ [[foo()]]类型名称;”的含义 C ++中的语法?

“对象Foo扩展(Bar => Baz)”是什么意思?

在Groovy中,“ foo?.bar”是什么意思?

('foo','bar')[sum(arr)%2]是什么意思?

IF AND OR C#的语法是什么

Clojure中的:foo,:: foo,:: bar / foo和:bar / foo有什么区别?