deleted-functions

Deletion of copy-ctor & copy-assignment - public, private or protected?

青春壹個敷衍的年華 提交于 2019-11-27 21:37:45
问题 In order to make an object non-copiable we can explicitly delete both its copy-constructor and copy-assignment operator. My question is: What is the right place to do it - in the public , private or protected section of the class? And - does this choice make any difference? 回答1: what is the right place to do it - in the public, private or protected section of the class? I would put them in the public section . This is because deleting a constructor or an assignment operator is orthogonal to

Specialized template function with deleted “general” case fails to compile with g++ <=4.8.0 and clang++

醉酒当歌 提交于 2019-11-27 15:01:06
Compiling a project with an older version of g++ (4.8.0, MinGW) I found that this code fails to compile: template<typename T> void foo() = delete; template<> void foo<int>(){} int main() { foo<int>(); return 0; } It seems that g++ doesn't even try to look for explicit specializations if it sees that the base case is deleted. mitalia@mitalia:~/scratch$ /opt/mingw32-dw2/bin/i686-w64-mingw32-g++ -std=c++11 buggy_deleted_template.cpp buggy_deleted_template.cpp: In function 'int main()': buggy_deleted_template.cpp:8:14: error: use of deleted function 'void foo() [with T = int]' foo<int>(); ^ buggy

Default move constructor/assignment and deleted copy constructor/assignment

自古美人都是妖i 提交于 2019-11-27 08:52:57
According to the standard, If the definition of a class X does not explicitly declare a move constructor, one will be implicitly declared as defaulted if and only if — X does not have a user-declared copy constructor, — X does not have a user-declared copy assignment operator, — X does not have a user-declared move assignment operator, and — X does not have a user-declared destructor. Now the following fails to compile # include <utility> class Foo { public: Foo() = default; Foo(Foo const &) = delete; }; int main() { Foo f; Foo g(std::move(f)); // compilation fails here return 0; } So it seems

error: use of deleted function

别等时光非礼了梦想. 提交于 2019-11-27 04:14:08
问题 I've been working on some C++ code that a friend has written and I get the following error that I have never seen before when compiling with gcc4.6: error: use of deleted function ‘GameFSM_<std::array<C, 2ul> >::hdealt::hdealt()’ is implicitly deleted because the default definition would be ill-formed: uninitialized non-static const member ‘const h_t FlopPokerGameFSM_<std::array<C, 2ul> >::hdealt::h’ Edit: This comes from a part of the code using boost MSM: Boost Webpage Edit2: There is no =

How is “=default” different from “{}” for default constructor and destructor?

别来无恙 提交于 2019-11-26 03:03:11
问题 I originally posted this as a question only about destructors, but now I\'m adding consideration of the default constructor. Here\'s the original question: If I want to give my class a destructor that is virtual, but is otherwise the same as what the compiler would generate, I can use =default : class Widget { public: virtual ~Widget() = default; }; But it seems that I can get the same effect with less typing using an empty definition: class Widget { public: virtual ~Widget() {} }; Is there