Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有一种通用的方法可以得到一个和的标识操作数。如果T是类型,则T{}返回此操作数。T{} + T{} == T{}例子:int{} == 0
T
T{}
T{} + T{} == T{}
int{} == 0
C++ 中是否还有一种通用方法来识别产品的标识操作数?
该符号T{}可能呈现value-initialization。要获得您所要求的,您需要实现您的类,以便默认构造函数返回产品运算符的标识(这意味着该标识T{} + T{} == T{}将不再为真)。