0

最近リリースされた C++ プログラミング言語第 4 版を調べて、新機能をチェックしています。私はVS2012 Update 3(VC11)コンパイラを使用しています(理想的ではありませんが、使用する必要があります)。

17.6 デフォルト操作状態の生成:

• If the programmer declares any constructor for a class, the default constructor
is not generated for that class.

• If the programmer declares a copy operation, a move operation, or a destructor
for a class, no copy operation, move operation, or destructor is generated for
that class.

これを読んだ場合、クラスのコピー コンストラクターを宣言すると、コンパイラーがコピーおよび移動操作を生成し、デストラクタはすべて抑制されます。

しかし、VS2012 では次のように表示されます。

struct H{}; // Compiler generated default, copy and move constructors, and
            // destructor. 

struct J
{
    explicit J(int){}
    J(const J&){}   // User copy constructor, so compiler generated default,
                    // copy or move operations and destructor should be
                    // suppressed.
};

void Foo()
{
    H h1;               // Compiler generated default construct.
    H h2 = h1;          // Compiler generated copy construct;
    h1 = h2;            // Compiler generated copy assign.
    H h3 = move(h1);    // Compiler generated move construct.
    h3 = move(h2);      // Compiler generated move assign.

//  J j1;               // Correct. Does not compile. No compiler generated default
                        // constructor.
    J j2(1);            // User constructor.
    J j3 = j2;          // User copy constructor.
    j2 = j3;            // Error? Generated copy assignment should be suppressed.
    J j4 = move(j2);    // Error? Generated move constructor should be suppressed.
    j3 = move(j4);      // Error? Generated move assignment should be suppressed.
}

それで、私は誤解しましたか、それとも本またはコンパイラが間違っていますか?

4

0 に答える 0