deleted-functions

Can any function be a deleted-function?

时间秒杀一切 提交于 2019-12-07 05:06:35
问题 The working draft explicitly calls out that defaulted-functions must be special member functions (eg copy-constructor, default-constructor, etc, (§8.4.2.1-1)). Which makes perfect sense. However, I don't see any such restriction on deleted-functions (§8.4.3). Is that right? Or in other words are these three examples valid c++0 ? struct Foo { // 1 int bar( int ) = delete; }; // 2 int baz( int ) = delete; template< typename T > int boo( T t ); // 3 template<> int boo<int>(int t) = delete; 回答1:

error C2280: attempting to reference a deleted function

不问归期 提交于 2019-12-05 17:34:35
问题 I'm new to game development and very new to c++, but I've started developing a little Arkanoid game. I've had it running previously, but after refactoring (introducing the ArkanoidGame class) it doesnt compile and I cannot figure out why. The error I'm getting is: d:\dropbox\development\gamedev\c++\arkanoid\arkanoid\main.cpp(14): error C2280: 'ArkanoidGame::ArkanoidGame(void)' : attempting to reference a deleted function d:\dropbox\development\gamedev\c++\arkanoid\arkanoid\arkanoidgame.h(25)

Are there any use cases for a class which is copyable but not movable?

大兔子大兔子 提交于 2019-12-04 23:41:15
After reading this recent question by @Mehrdad on which classes should be made non-movable and therefore non-copyable , I starting wondering if there are use cases for a class which can be copied but not moved . Technically, this is possible: struct S { S() { } S(S const& s) { } S(S&&) = delete; }; S foo() { S s1; S s2(s1); // OK (copyable) return s1; // ERROR! (non-movable) } Although S has a copy constructor, it obviously does not model the CopyConstructible concept, because that is in turn a refinement of the MoveConstructible concept, which requires the presence of a (non-deleted) move

Danger with virtual base move assignment operators when they are now allowed to be used?

好久不见. 提交于 2019-12-04 09:38:10
This concerns the resolution of C++ Issue http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1402 . Summary: template<typename T> struct wrap { wrap() = default; wrap(wrap&&) = default; wrap(const wrap&) = default; T t; }; struct S { S(){} S(const S&){} S(S&&){} }; typedef wrap<const S> W; // Error, defaulted move constructor of "wrap<const S>" is deleted! W get() { return W(); } (The issue is that we are getting an error for this snippet, even though the compiler could simply use the copy constructor of "S", as it does when the user explicitly writes the move constructor of "wrap".

error C2280: attempting to reference a deleted function

拥有回忆 提交于 2019-12-04 01:57:04
I'm new to game development and very new to c++, but I've started developing a little Arkanoid game. I've had it running previously, but after refactoring (introducing the ArkanoidGame class) it doesnt compile and I cannot figure out why. The error I'm getting is: d:\dropbox\development\gamedev\c++\arkanoid\arkanoid\main.cpp(14): error C2280: 'ArkanoidGame::ArkanoidGame(void)' : attempting to reference a deleted function d:\dropbox\development\gamedev\c++\arkanoid\arkanoid\arkanoidgame.h(25) : compiler has generated 'ArkanoidGame::ArkanoidGame' here I simply dont understand what this means and

Is there any point in declaring a deleted function as noexcept?

二次信任 提交于 2019-12-01 15:43:09
Consider these two possible definitions for a class: Exhibit A: struct A { A() = delete; }; Exhibit A′: struct A { A() noexcept = delete; } Is there any point in declaring a deleted function as noexcept ? (Posted this initially as a comment, but encouraged to post as an answer.) Simply, no. A function that is deleted cannot be called (or, in the case of a constructor, used to initialise an object) let alone throw an exception. Edit: hvd mentioned in comments below that noexcept(f()) does not call f() . If the constructor of class A is delete d, then noexcept(A()) will fail to compile,

Is there any point in declaring a deleted function as noexcept?

萝らか妹 提交于 2019-12-01 14:33:09
问题 Consider these two possible definitions for a class: Exhibit A: struct A { A() = delete; }; Exhibit A′: struct A { A() noexcept = delete; } Is there any point in declaring a deleted function as noexcept ? 回答1: (Posted this initially as a comment, but encouraged to post as an answer.) Simply, no. A function that is deleted cannot be called (or, in the case of a constructor, used to initialise an object) let alone throw an exception. Edit: hvd mentioned in comments below that noexcept(f()) does

Why can't an object containing a ostringstream member be constructed?

自作多情 提交于 2019-12-01 08:43:48
I have the following class example, simplified from a larger project. It's based on a logging framework that uses the logger's scope to terminate a log entry in the destructor. The code below will not compile because the constructor is an implicitly deleted function ( edit: not true ), which seems to have something to do with the std::ostringstream object. I'm confused about that because I think I should be able to directly construct a std::ostringstream , which would mean I should be able to directly construct a Container object. #include <iostream> #include <sstream> class Container { public

Why can't an object containing a ostringstream member be constructed?

半腔热情 提交于 2019-12-01 06:25:44
问题 I have the following class example, simplified from a larger project. It's based on a logging framework that uses the logger's scope to terminate a log entry in the destructor. The code below will not compile because the constructor is an implicitly deleted function ( edit: not true ), which seems to have something to do with the std::ostringstream object. I'm confused about that because I think I should be able to directly construct a std::ostringstream , which would mean I should be able to

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

℡╲_俬逩灬. 提交于 2019-11-29 01:00:39
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? 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 making them private / protected ; and when these aren't deleted, they are public by default. Putting the