When designing a class that can be moved but not copied, it’s natural to declare the copy constructor as private. When having only movable and trivially copyable objects as instance members, it makes sense to allow the compiler to implicitly generate the move constructor.
However, when supporting both VS11 and G++4.7 I found an incompatibility:
- VS11 requires explicitly defined move constructors
- G++ requires explicit move constructors to have either matching public copy constructor or the noexcept keyword.
- VS11 doesn’t support the noexcept keyword.
As you can see, this places me in a bit of a pickle. My class must not be copied. I must support both VS11 and MinGW / GCC. I need my class to be movable.
Have I misunderstood something, or is there a way around this tiny problem? Can I make compilation fail if a call to the copy constructor is generated? Any better solution to this problem?
If you add this to the source file
You will be able to define it as
noexcepton GCC but VC++ will ignorenoexcept.