C++ C++;传递函数参数时的执行顺序
具有以下接口的容器类:C++ C++;传递函数参数时的执行顺序,c++,function,expression,iso,C++,Function,Expression,Iso,具有以下接口的容器类: template <typename T> class DynArray { /// Returns the number of elements in the array. inline size_t GetCount(); /// Releases the internal memory from the \class DynArray /// and returns it. The memory must be deallocated m
template <typename T> class DynArray {
/// Returns the number of elements in the array.
inline size_t GetCount();
/// Releases the internal memory from the \class DynArray
/// and returns it. The memory must be deallocated manually.
inline T* Release();
}
我本来希望在arr.Release()
之前调用arr.GetCount()
,但实际情况似乎相反,导致第一个参数被传递一个值0
,而不是实际的数组大小。我正在使用Visual Studio 2012
C++标准是否在评估函数参数时说了具体的执行顺序?
< P>,它表示顺序完全未指定。< /P> 排序规则太复杂,无法在这里复制,很难证明是否定的,但非规范性注释方便地为我们总结了它:[C++11:5.2.2/4]:
调用函数时,每个参数(8.3.5)应使用相应的参数初始化(8.5、12.8、12.1)。[注:此类初始化相互之间的顺序不确定(1.9)-结束注][…]
(与C++14中的文本相同。)当作为参数传递时,标准不强制执行顺序,这由实现者决定:
SomeFunction(arr.GetCount(), arr.Release())