Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 奇怪';新';建造师_C++_Qt - Fatal编程技术网

C++ 奇怪';新';建造师

C++ 奇怪';新';建造师,c++,qt,C++,Qt,我在检查Qt源代码时遇到以下代码: template <typename T> Q_INLINE_TEMPLATE void QList<T>::node_construct(Node *n, const T &t) { if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) n->v = new T(t); else if (QTypeInfo<T>::i

我在检查Qt源代码时遇到以下代码:

template <typename T>
Q_INLINE_TEMPLATE void QList<T>::node_construct(Node *n, const T &t)
{
    if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) n->v = new T(t);
    else if (QTypeInfo<T>::isComplex) new (n) T(t);
#if (defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__IBMCPP__)) && !defined(__OPTIMIZE__)
    // This violates pointer aliasing rules, but it is known to be safe (and silent)
    // in unoptimized GCC builds (-fno-strict-aliasing). The other compilers which
    // set the same define are assumed to be safe.
    else *reinterpret_cast<T*>(n) = t;
#else
    // This is always safe, but penaltizes unoptimized builds a lot.
    else ::memcpy(n, static_cast<const void *>(&t), sizeof(T));
#endif
}

据我所知,这似乎不是一个类型演员。这个结构是什么意思?

这是新的。它只是用一个地址调用一个构造函数。因此,将在位置
n
处构造类型为
T
的对象。它看起来也是一个调用副本构造函数的新位置

new (n) T(t);