【发布时间】:2015-05-20 10:59:07
【问题描述】:
具有以下接口的容器类:
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();
}
在函数调用中
SomeFunction(arr.GetCount(), arr.Release())
我原以为arr.GetCount() 会在arr.Release() 之前被调用,但实际上似乎发生了相反的情况,导致第一个参数被传递了0 的值而不是实际的数组大小。我正在使用 Visual Studio 2012。
在评估函数参数时,C++ 标准是否对执行顺序有任何具体规定?
【问题讨论】:
-
标准没有规定作为参数传递时的执行顺序,这留给实现者:stackoverflow.com/questions/2934904/…
标签: c++ function expression iso