array initialization, is referencing a previous element ok?

前端 未结 4 1915
耶瑟儿~
耶瑟儿~ 2020-12-11 16:26
const QPointF points[] =
{
    QPointF(r.left() - i, r.top() - i),
    QPointF(r.right() + i, r.top() - i),
    QPointF(r.right() + i, r.bottom() + i),
    QPointF(r         


        
4条回答
  •  醉话见心
    2020-12-11 17:20

    Old Answer (misses the point):

    I checked the current C++0x draft, and there i found the sentence 8.5.1.17 which says:

    17 The full-expressions in an initializer-clause are evaluated in the order in which they appear.

    So while this sentence is not part of the C++ Standard from 2003, im quite sure that this should be working in any up to date compiler, if this is part of C++0x.

    Edit:
    The comments made me rethink this matter. This line only ensures that the QPointF objects are created in the order in which they occur in the array initialization (relevant if the element constructors have observable side-effects). The problem is, the value of points is indeterminate during its array initialization. So there cant be a guarantee for a valid value of points[0] either, at least not if you rely on the standard.

提交回复
热议问题