本文介绍了使用“成员空间”成语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我学习了C ++的成员空间成语,它大致滥用了C ++的属性,使得 T :: bar 以及 T .bar 工作, T 既是某种范围内的类型和对象。

Today I learned about the C++ "memberspace" idiom, which roughly abuses a property of C++ that makes T::bar as well as T.bar work, when T is both a type and an object in some scope.

struct A {
  struct Controls {
    /* put some typedefs/data/functions here */
  } Controls;
};

// Can be used as a type and value
A a;
A::Controls::iterator it = a.Controls.begin();

你在实践中曾经使用过这个成语吗?你发现它有用吗?

Have you ever used this idiom in practice? Have you found it useful? What's some good or the best application of the idiom?

推荐答案

不,我从来没有使用过这种技术认为它应该被称为成语):

No, I have never used that technique (and I don't think it deserves to be called an "idiom"):

由于我没有使用它,我没有发现它有用。

Since I haven't used it, I haven't found it useful.

这种技术的一个很好的应用可能是混淆其他程序员。

A good application of that technique could be to confuse other programmers.

另一个应用可能是写一篇关于如何精彩的技术文章这是一些想象中从来没有在实践中遇到的问题,也许混淆了大量的模板元编程。

Another application could be to write a techno-babble article about how wonderful it is for some imagined never-in-practice encountered problem, perhaps obfuscated with lots of template metaprogramming?

Dunno,最好的应用程序可能是写一篇关于所有愚蠢的规则,像你也可以有一个 struct 和一个同名的函数在同一个范围,我记得,指出那些可以完成什么,可以通过远离语言的较暗角落来更好地完成。 :-)文章不付出太多的钱,但他们支付方面,是有趣的写。请写下(TIA)。

Dunno, best application would probably be to write an article about all those silly-rules, like you can also have a struct and a function of the same name in the same scope, as I recall, and point out how anything that those can accomplish, can be accomplished much better by staying away from the darker corners of the language. :-) Articles don't pay much in moneys but they pay in respect and are fun to write. Please write it (TIA).

干杯& hth。,

这篇关于使用“成员空间”成语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 09:33