数据成员是否形成范围? [英] Do data members form a range?
本文介绍了数据成员是否形成范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将相同类型的连续数据成员视为一个范围吗?例如:
Can I treat consecutive data members of the same type as a range? For example:
struct X
{
int a, b, c, d, e;
};
X x = {42, 13, 97, 11, 31};
std::sort(&x.a, &x.a + 5); // kosher?
推荐答案
否,这是未定义的行为.您将x.a
视为数组的第一个元素,实际上并非如此.可能在某些实现上可行,也可能袭击您的冰箱;)
No, this is undefined behaviour. You are treating x.a
like the first element of an array, which it isn't. May work on some implementations, may raid your fridge too ;)
这篇关于数据成员是否形成范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文