Skip to content

Instantly share code, notes, and snippets.

@laverdet
Created February 5, 2018 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laverdet/605399df8d837cdcd4107c3aaa7db09b to your computer and use it in GitHub Desktop.
Save laverdet/605399df8d837cdcd4107c3aaa7db09b to your computer and use it in GitHub Desktop.
marcel@localhost ~/isolated-vm $ g++ thing.cc -std=c++11
thing.cc: In instantiation of 'void MakeThing(Args&& ...) [with Args = {}]':
thing.cc:16:12: required from here
thing.cc:12:44: error: use of deleted function 'Thing::Thing(const Thing&)'
Thing instance(std::forward<Args>(args)...);
^
thing.cc:5:2: note: declared here
Thing(const Thing&) = delete;
^
marcel@localhost ~/isolated-vm $ g++ --version
g++ (Gentoo 5.4.0-r3 p1.3, pie-0.6.5) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#include <utility>
struct Thing {
Thing() = default;
Thing(const Thing&) = delete;
// It works fine if you don't have any virtual methods
virtual ~Thing() = default;
};
template <typename ...Args>
void MakeThing(Args&&... args) {
Thing instance(std::forward<Args>(args)...);
}
int main() {
MakeThing();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment