Skip to content

Instantly share code, notes, and snippets.

@tomjakubowski
Created January 25, 2016 01:46
Show Gist options
  • Save tomjakubowski/f9eb979949402ec9eccd to your computer and use it in GitHub Desktop.
Save tomjakubowski/f9eb979949402ec9eccd to your computer and use it in GitHub Desktop.
Debugger entered--Lisp error: (quit)
replace-regexp-in-string("[[:space:]]+\\'" "" "lass, when that classes uses the PIMPL pattern.\n\nFoo.h:\n\n")
sx-babel--make-pre-button(427 370)
sx-question-mode--skip-and-fontify-pre()
sx-question-mode--dont-fill-here()
sx-question-mode--process-markdown-in-region(283 2215)
sx-question-mode--insert-markdown("I'm getting a compile error in Visual Studio 2015 when I try to declare a variable of class, when that classes uses the PIMPL pattern.\n\nFoo.h:\n\n #pragma once\n\n class Foo\n {\n public:\n Foo(const std::wstring& str,\n const std::vector<std::wstring>& items);\n ~Foo();\n\n private:\n struct Impl;\n std::unique_ptr<Impl> pimpl;\n };\n\nFoo.cpp:\n\n #include \"stdafx.h\"\n #include \"Foo.h\"\n\n struct Foo::Impl\n {\n public:\n Impl(const std::wstring& str,\n const std::vector<std::wstring>& items);\n\n std::wstring str_;\n std::vector<std::wstring> items_;\n };\n\n Foo::Foo(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : pimpl(std::make_unique<Impl>(str, items))\n {\n }\n\n Foo::~Foo() = default;\n\n Foo::Impl::Impl(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : str_(str),\n items_(items)\n {\n }\n\nIf I declare a variable of type `Foo` using the traditional syntax, it compiles fine:\n\n Foo f(L\"Hello\", std::vector<std::wstring>());\n\nHowever, if I declare it using `auto`, then I get a compile error:\n\n auto f2 = Foo { L\"Goodbye\", std::vector<std::wstring>() };\n\n> error C2280: 'Foo::Foo(const Foo &)': attempting to reference a deleted function \n> note: compiler has generated 'Foo::Foo' here\n\nI understand that the copy constructor for `Foo` should be deleted, since `unique_ptr` can't be copied. However, it was my understanding that when declaring variables in this way, the result would be either moved into the variable or just set the value into the variable directly.\n\nThe second line compiles fine when using Visual Studio 2013. I checked the breaking changes in Visual Studio 2015, but I didn't see anything there that would indicate why this started failing.\n\nAm I doing something wrong, or can this syntax not be used with non-copyable types?")
sx-question-mode--print-section(((title . "Why can't I declare a variable using auto?") (site_par . "stackoverflow") (link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto") (body_markdown . "I'm getting a compile error in Visual Studio 2015 when I try to declare a variable of class, when that classes uses the PIMPL pattern.\n\nFoo.h:\n\n #pragma once\n\n class Foo\n {\n public:\n Foo(const std::wstring& str,\n const std::vector<std::wstring>& items);\n ~Foo();\n\n private:\n struct Impl;\n std::unique_ptr<Impl> pimpl;\n };\n\nFoo.cpp:\n\n #include \"stdafx.h\"\n #include \"Foo.h\"\n\n struct Foo::Impl\n {\n public:\n Impl(const std::wstring& str,\n const std::vector<std::wstring>& items);\n\n std::wstring str_;\n std::vector<std::wstring> items_;\n };\n\n Foo::Foo(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : pimpl(std::make_unique<Impl>(str, items))\n {\n }\n\n Foo::~Foo() = default;\n\n Foo::Impl::Impl(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : str_(str),\n items_(items)\n {\n }\n\nIf I declare a variable of type `Foo` using the traditional syntax, it compiles fine:\n\n Foo f(L\"Hello\", std::vector<std::wstring>());\n\nHowever, if I declare it using `auto`, then I get a compile error:\n\n auto f2 = Foo { L\"Goodbye\", std::vector<std::wstring>() };\n\n> error C2280: 'Foo::Foo(const Foo &)': attempting to reference a deleted function \n> note: compiler has generated 'Foo::Foo' here\n\nI understand that the copy constructor for `Foo` should be deleted, since `unique_ptr` can't be copied. However, it was my understanding that when declaring variables in this way, the result would be either moved into the variable or just set the value into the variable directly.\n\nThe second line compiles fine when using Visual Studio 2013. I checked the breaking changes in Visual Studio 2015, but I didn't see anything there that would indicate why this started failing.\n\nAm I doing something wrong, or can this syntax not be used with non-copyable types?") (share_link . "http://stackoverflow.com/q/34858457/692055") (question_id . 34858457) (last_edit_date . 1453131941) (creation_date . 1453131263) (last_activity_date . 1453131941) (score . 4) (answer_count . 2) (accepted_answer_id . 34858568) (view_count . 187) (is_answered . t) (upvoted) (downvoted) (last_editor (link . "http://stackoverflow.com/users/636019/ildjarn") (display_name . "ildjarn") (profile_image . "https://www.gravatar.com/avatar/38ba39c7ba510ac2951c010c26afb6a6?s=128&d=identicon&r=PG") (user_type . "registered") (user_id . 636019) (reputation . 42901)) (owner (link . "http://stackoverflow.com/users/3857/andy") (display_name . "Andy") (profile_image . "https://www.gravatar.com/avatar/21599de27f8bc6cc7e9b3d002addbca8?s=128&d=identicon&r=PG") (accept_rate . 100) (user_type . "registered") (user_id . 3857) (reputation . 18755)) (answers ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858538#34858538") (body_markdown . "Because the class contains a [`std::unique_ptr`](http://en.cppreference.com/w/cpp/memory/unique_ptr) member the compiler can't generate a copy-constructor like it would normally do, which means your declaration and initialization (which invokes the copy-constructor) will not be possible.\n\nYou could solve it by making a [move constructor](http://en.cppreference.com/w/cpp/language/move_constructor) for your class and mark it as `default`.") (share_link . "http://stackoverflow.com/a/34858538/692055") (question_id . 34858457) (answer_id . 34858538) (creation_date . 1453131440) (last_activity_date . 1453131440) (score . 5) (is_accepted) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/440558/joachim-pileborg") (display_name . "Joachim Pileborg") (profile_image . "https://i.stack.imgur.com/9ZYta.jpg?s=128&g=1") (accept_rate . 75) (user_type . "registered") (user_id . 440558) (reputation . 177029))) ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858568#34858568") (body_markdown . "The move constructor is not implicitly declared, because you have a user-declared destructor (see [[class.copy]/(9.4)][1]). However, the copy constructor is clearly deleted, since `unique_ptr` can't be copied.\n\nYou can explicitly declare the move constructor as defaulted.\n\n\n [1]: http://eel.is/c++draft/class.copy#9") (share_link . "http://stackoverflow.com/a/34858568/692055") (question_id . 34858457) (answer_id . 34858568) (creation_date . 1453131565) (last_activity_date . 1453131565) (score . 10) (is_accepted . t) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/3647361/columbo") (display_name . "Columbo") (profile_image . "https://i.stack.imgur.com/xvjhM.png?s=128&g=1") (accept_rate . 83) (user_type . "registered") (user_id . 3647361) (reputation . 35995)))) (tags "c++" "c++11" "visual-c++" "visual-studio-2015" "move-semantics")))
sx-question-mode--print-question(((title . "Why can't I declare a variable using auto?") (site_par . "stackoverflow") (link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto") (body_markdown . "I'm getting a compile error in Visual Studio 2015 when I try to declare a variable of class, when that classes uses the PIMPL pattern.\n\nFoo.h:\n\n #pragma once\n\n class Foo\n {\n public:\n Foo(const std::wstring& str,\n const std::vector<std::wstring>& items);\n ~Foo();\n\n private:\n struct Impl;\n std::unique_ptr<Impl> pimpl;\n };\n\nFoo.cpp:\n\n #include \"stdafx.h\"\n #include \"Foo.h\"\n\n struct Foo::Impl\n {\n public:\n Impl(const std::wstring& str,\n const std::vector<std::wstring>& items);\n\n std::wstring str_;\n std::vector<std::wstring> items_;\n };\n\n Foo::Foo(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : pimpl(std::make_unique<Impl>(str, items))\n {\n }\n\n Foo::~Foo() = default;\n\n Foo::Impl::Impl(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : str_(str),\n items_(items)\n {\n }\n\nIf I declare a variable of type `Foo` using the traditional syntax, it compiles fine:\n\n Foo f(L\"Hello\", std::vector<std::wstring>());\n\nHowever, if I declare it using `auto`, then I get a compile error:\n\n auto f2 = Foo { L\"Goodbye\", std::vector<std::wstring>() };\n\n> error C2280: 'Foo::Foo(const Foo &)': attempting to reference a deleted function \n> note: compiler has generated 'Foo::Foo' here\n\nI understand that the copy constructor for `Foo` should be deleted, since `unique_ptr` can't be copied. However, it was my understanding that when declaring variables in this way, the result would be either moved into the variable or just set the value into the variable directly.\n\nThe second line compiles fine when using Visual Studio 2013. I checked the breaking changes in Visual Studio 2015, but I didn't see anything there that would indicate why this started failing.\n\nAm I doing something wrong, or can this syntax not be used with non-copyable types?") (share_link . "http://stackoverflow.com/q/34858457/692055") (question_id . 34858457) (last_edit_date . 1453131941) (creation_date . 1453131263) (last_activity_date . 1453131941) (score . 4) (answer_count . 2) (accepted_answer_id . 34858568) (view_count . 187) (is_answered . t) (upvoted) (downvoted) (last_editor (link . "http://stackoverflow.com/users/636019/ildjarn") (display_name . "ildjarn") (profile_image . "https://www.gravatar.com/avatar/38ba39c7ba510ac2951c010c26afb6a6?s=128&d=identicon&r=PG") (user_type . "registered") (user_id . 636019) (reputation . 42901)) (owner (link . "http://stackoverflow.com/users/3857/andy") (display_name . "Andy") (profile_image . "https://www.gravatar.com/avatar/21599de27f8bc6cc7e9b3d002addbca8?s=128&d=identicon&r=PG") (accept_rate . 100) (user_type . "registered") (user_id . 3857) (reputation . 18755)) (answers ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858538#34858538") (body_markdown . "Because the class contains a [`std::unique_ptr`](http://en.cppreference.com/w/cpp/memory/unique_ptr) member the compiler can't generate a copy-constructor like it would normally do, which means your declaration and initialization (which invokes the copy-constructor) will not be possible.\n\nYou could solve it by making a [move constructor](http://en.cppreference.com/w/cpp/language/move_constructor) for your class and mark it as `default`.") (share_link . "http://stackoverflow.com/a/34858538/692055") (question_id . 34858457) (answer_id . 34858538) (creation_date . 1453131440) (last_activity_date . 1453131440) (score . 5) (is_accepted) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/440558/joachim-pileborg") (display_name . "Joachim Pileborg") (profile_image . "https://i.stack.imgur.com/9ZYta.jpg?s=128&g=1") (accept_rate . 75) (user_type . "registered") (user_id . 440558) (reputation . 177029))) ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858568#34858568") (body_markdown . "The move constructor is not implicitly declared, because you have a user-declared destructor (see [[class.copy]/(9.4)][1]). However, the copy constructor is clearly deleted, since `unique_ptr` can't be copied.\n\nYou can explicitly declare the move constructor as defaulted.\n\n\n [1]: http://eel.is/c++draft/class.copy#9") (share_link . "http://stackoverflow.com/a/34858568/692055") (question_id . 34858457) (answer_id . 34858568) (creation_date . 1453131565) (last_activity_date . 1453131565) (score . 10) (is_accepted . t) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/3647361/columbo") (display_name . "Columbo") (profile_image . "https://i.stack.imgur.com/xvjhM.png?s=128&g=1") (accept_rate . 83) (user_type . "registered") (user_id . 3647361) (reputation . 35995)))) (tags "c++" "c++11" "visual-c++" "visual-studio-2015" "move-semantics")))
sx-question-mode--erase-and-print-question(((title . "Why can't I declare a variable using auto?") (site_par . "stackoverflow") (link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto") (body_markdown . "I'm getting a compile error in Visual Studio 2015 when I try to declare a variable of class, when that classes uses the PIMPL pattern.\n\nFoo.h:\n\n #pragma once\n\n class Foo\n {\n public:\n Foo(const std::wstring& str,\n const std::vector<std::wstring>& items);\n ~Foo();\n\n private:\n struct Impl;\n std::unique_ptr<Impl> pimpl;\n };\n\nFoo.cpp:\n\n #include \"stdafx.h\"\n #include \"Foo.h\"\n\n struct Foo::Impl\n {\n public:\n Impl(const std::wstring& str,\n const std::vector<std::wstring>& items);\n\n std::wstring str_;\n std::vector<std::wstring> items_;\n };\n\n Foo::Foo(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : pimpl(std::make_unique<Impl>(str, items))\n {\n }\n\n Foo::~Foo() = default;\n\n Foo::Impl::Impl(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : str_(str),\n items_(items)\n {\n }\n\nIf I declare a variable of type `Foo` using the traditional syntax, it compiles fine:\n\n Foo f(L\"Hello\", std::vector<std::wstring>());\n\nHowever, if I declare it using `auto`, then I get a compile error:\n\n auto f2 = Foo { L\"Goodbye\", std::vector<std::wstring>() };\n\n> error C2280: 'Foo::Foo(const Foo &)': attempting to reference a deleted function \n> note: compiler has generated 'Foo::Foo' here\n\nI understand that the copy constructor for `Foo` should be deleted, since `unique_ptr` can't be copied. However, it was my understanding that when declaring variables in this way, the result would be either moved into the variable or just set the value into the variable directly.\n\nThe second line compiles fine when using Visual Studio 2013. I checked the breaking changes in Visual Studio 2015, but I didn't see anything there that would indicate why this started failing.\n\nAm I doing something wrong, or can this syntax not be used with non-copyable types?") (share_link . "http://stackoverflow.com/q/34858457/692055") (question_id . 34858457) (last_edit_date . 1453131941) (creation_date . 1453131263) (last_activity_date . 1453131941) (score . 4) (answer_count . 2) (accepted_answer_id . 34858568) (view_count . 187) (is_answered . t) (upvoted) (downvoted) (last_editor (link . "http://stackoverflow.com/users/636019/ildjarn") (display_name . "ildjarn") (profile_image . "https://www.gravatar.com/avatar/38ba39c7ba510ac2951c010c26afb6a6?s=128&d=identicon&r=PG") (user_type . "registered") (user_id . 636019) (reputation . 42901)) (owner (link . "http://stackoverflow.com/users/3857/andy") (display_name . "Andy") (profile_image . "https://www.gravatar.com/avatar/21599de27f8bc6cc7e9b3d002addbca8?s=128&d=identicon&r=PG") (accept_rate . 100) (user_type . "registered") (user_id . 3857) (reputation . 18755)) (answers ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858538#34858538") (body_markdown . "Because the class contains a [`std::unique_ptr`](http://en.cppreference.com/w/cpp/memory/unique_ptr) member the compiler can't generate a copy-constructor like it would normally do, which means your declaration and initialization (which invokes the copy-constructor) will not be possible.\n\nYou could solve it by making a [move constructor](http://en.cppreference.com/w/cpp/language/move_constructor) for your class and mark it as `default`.") (share_link . "http://stackoverflow.com/a/34858538/692055") (question_id . 34858457) (answer_id . 34858538) (creation_date . 1453131440) (last_activity_date . 1453131440) (score . 5) (is_accepted) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/440558/joachim-pileborg") (display_name . "Joachim Pileborg") (profile_image . "https://i.stack.imgur.com/9ZYta.jpg?s=128&g=1") (accept_rate . 75) (user_type . "registered") (user_id . 440558) (reputation . 177029))) ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858568#34858568") (body_markdown . "The move constructor is not implicitly declared, because you have a user-declared destructor (see [[class.copy]/(9.4)][1]). However, the copy constructor is clearly deleted, since `unique_ptr` can't be copied.\n\nYou can explicitly declare the move constructor as defaulted.\n\n\n [1]: http://eel.is/c++draft/class.copy#9") (share_link . "http://stackoverflow.com/a/34858568/692055") (question_id . 34858457) (answer_id . 34858568) (creation_date . 1453131565) (last_activity_date . 1453131565) (score . 10) (is_accepted . t) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/3647361/columbo") (display_name . "Columbo") (profile_image . "https://i.stack.imgur.com/xvjhM.png?s=128&g=1") (accept_rate . 83) (user_type . "registered") (user_id . 3647361) (reputation . 35995)))) (tags "c++" "c++11" "visual-c++" "visual-studio-2015" "move-semantics")))
sx-question-mode--display(((title . "Why can't I declare a variable using auto?") (site_par . "stackoverflow") (link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto") (body_markdown . "I'm getting a compile error in Visual Studio 2015 when I try to declare a variable of class, when that classes uses the PIMPL pattern.\n\nFoo.h:\n\n #pragma once\n\n class Foo\n {\n public:\n Foo(const std::wstring& str,\n const std::vector<std::wstring>& items);\n ~Foo();\n\n private:\n struct Impl;\n std::unique_ptr<Impl> pimpl;\n };\n\nFoo.cpp:\n\n #include \"stdafx.h\"\n #include \"Foo.h\"\n\n struct Foo::Impl\n {\n public:\n Impl(const std::wstring& str,\n const std::vector<std::wstring>& items);\n\n std::wstring str_;\n std::vector<std::wstring> items_;\n };\n\n Foo::Foo(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : pimpl(std::make_unique<Impl>(str, items))\n {\n }\n\n Foo::~Foo() = default;\n\n Foo::Impl::Impl(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : str_(str),\n items_(items)\n {\n }\n\nIf I declare a variable of type `Foo` using the traditional syntax, it compiles fine:\n\n Foo f(L\"Hello\", std::vector<std::wstring>());\n\nHowever, if I declare it using `auto`, then I get a compile error:\n\n auto f2 = Foo { L\"Goodbye\", std::vector<std::wstring>() };\n\n> error C2280: 'Foo::Foo(const Foo &)': attempting to reference a deleted function \n> note: compiler has generated 'Foo::Foo' here\n\nI understand that the copy constructor for `Foo` should be deleted, since `unique_ptr` can't be copied. However, it was my understanding that when declaring variables in this way, the result would be either moved into the variable or just set the value into the variable directly.\n\nThe second line compiles fine when using Visual Studio 2013. I checked the breaking changes in Visual Studio 2015, but I didn't see anything there that would indicate why this started failing.\n\nAm I doing something wrong, or can this syntax not be used with non-copyable types?") (share_link . "http://stackoverflow.com/q/34858457/692055") (question_id . 34858457) (last_edit_date . 1453131941) (creation_date . 1453131263) (last_activity_date . 1453131941) (score . 4) (answer_count . 2) (accepted_answer_id . 34858568) (view_count . 187) (is_answered . t) (upvoted) (downvoted) (last_editor (link . "http://stackoverflow.com/users/636019/ildjarn") (display_name . "ildjarn") (profile_image . "https://www.gravatar.com/avatar/38ba39c7ba510ac2951c010c26afb6a6?s=128&d=identicon&r=PG") (user_type . "registered") (user_id . 636019) (reputation . 42901)) (owner (link . "http://stackoverflow.com/users/3857/andy") (display_name . "Andy") (profile_image . "https://www.gravatar.com/avatar/21599de27f8bc6cc7e9b3d002addbca8?s=128&d=identicon&r=PG") (accept_rate . 100) (user_type . "registered") (user_id . 3857) (reputation . 18755)) (answers ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858538#34858538") (body_markdown . "Because the class contains a [`std::unique_ptr`](http://en.cppreference.com/w/cpp/memory/unique_ptr) member the compiler can't generate a copy-constructor like it would normally do, which means your declaration and initialization (which invokes the copy-constructor) will not be possible.\n\nYou could solve it by making a [move constructor](http://en.cppreference.com/w/cpp/language/move_constructor) for your class and mark it as `default`.") (share_link . "http://stackoverflow.com/a/34858538/692055") (question_id . 34858457) (answer_id . 34858538) (creation_date . 1453131440) (last_activity_date . 1453131440) (score . 5) (is_accepted) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/440558/joachim-pileborg") (display_name . "Joachim Pileborg") (profile_image . "https://i.stack.imgur.com/9ZYta.jpg?s=128&g=1") (accept_rate . 75) (user_type . "registered") (user_id . 440558) (reputation . 177029))) ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858568#34858568") (body_markdown . "The move constructor is not implicitly declared, because you have a user-declared destructor (see [[class.copy]/(9.4)][1]). However, the copy constructor is clearly deleted, since `unique_ptr` can't be copied.\n\nYou can explicitly declare the move constructor as defaulted.\n\n\n [1]: http://eel.is/c++draft/class.copy#9") (share_link . "http://stackoverflow.com/a/34858568/692055") (question_id . 34858457) (answer_id . 34858568) (creation_date . 1453131565) (last_activity_date . 1453131565) (score . 10) (is_accepted . t) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/3647361/columbo") (display_name . "Columbo") (profile_image . "https://i.stack.imgur.com/xvjhM.png?s=128&g=1") (accept_rate . 83) (user_type . "registered") (user_id . 3647361) (reputation . 35995)))) (tags "c++" "c++11" "visual-c++" "visual-studio-2015" "move-semantics")) nil)
sx-display-question(((title . "Why can't I declare a variable using auto?") (site_par . "stackoverflow") (link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto") (body_markdown . "I'm getting a compile error in Visual Studio 2015 when I try to declare a variable of class, when that classes uses the PIMPL pattern.\n\nFoo.h:\n\n #pragma once\n\n class Foo\n {\n public:\n Foo(const std::wstring& str,\n const std::vector<std::wstring>& items);\n ~Foo();\n\n private:\n struct Impl;\n std::unique_ptr<Impl> pimpl;\n };\n\nFoo.cpp:\n\n #include \"stdafx.h\"\n #include \"Foo.h\"\n\n struct Foo::Impl\n {\n public:\n Impl(const std::wstring& str,\n const std::vector<std::wstring>& items);\n\n std::wstring str_;\n std::vector<std::wstring> items_;\n };\n\n Foo::Foo(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : pimpl(std::make_unique<Impl>(str, items))\n {\n }\n\n Foo::~Foo() = default;\n\n Foo::Impl::Impl(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : str_(str),\n items_(items)\n {\n }\n\nIf I declare a variable of type `Foo` using the traditional syntax, it compiles fine:\n\n Foo f(L\"Hello\", std::vector<std::wstring>());\n\nHowever, if I declare it using `auto`, then I get a compile error:\n\n auto f2 = Foo { L\"Goodbye\", std::vector<std::wstring>() };\n\n> error C2280: 'Foo::Foo(const Foo &)': attempting to reference a deleted function \n> note: compiler has generated 'Foo::Foo' here\n\nI understand that the copy constructor for `Foo` should be deleted, since `unique_ptr` can't be copied. However, it was my understanding that when declaring variables in this way, the result would be either moved into the variable or just set the value into the variable directly.\n\nThe second line compiles fine when using Visual Studio 2013. I checked the breaking changes in Visual Studio 2015, but I didn't see anything there that would indicate why this started failing.\n\nAm I doing something wrong, or can this syntax not be used with non-copyable types?") (share_link . "http://stackoverflow.com/q/34858457/692055") (question_id . 34858457) (last_edit_date . 1453131941) (creation_date . 1453131263) (last_activity_date . 1453131941) (score . 4) (answer_count . 2) (accepted_answer_id . 34858568) (view_count . 187) (is_answered . t) (upvoted) (downvoted) (last_editor (link . "http://stackoverflow.com/users/636019/ildjarn") (display_name . "ildjarn") (profile_image . "https://www.gravatar.com/avatar/38ba39c7ba510ac2951c010c26afb6a6?s=128&d=identicon&r=PG") (user_type . "registered") (user_id . 636019) (reputation . 42901)) (owner (link . "http://stackoverflow.com/users/3857/andy") (display_name . "Andy") (profile_image . "https://www.gravatar.com/avatar/21599de27f8bc6cc7e9b3d002addbca8?s=128&d=identicon&r=PG") (accept_rate . 100) (user_type . "registered") (user_id . 3857) (reputation . 18755)) (answers ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858538#34858538") (body_markdown . "Because the class contains a [`std::unique_ptr`](http://en.cppreference.com/w/cpp/memory/unique_ptr) member the compiler can't generate a copy-constructor like it would normally do, which means your declaration and initialization (which invokes the copy-constructor) will not be possible.\n\nYou could solve it by making a [move constructor](http://en.cppreference.com/w/cpp/language/move_constructor) for your class and mark it as `default`.") (share_link . "http://stackoverflow.com/a/34858538/692055") (question_id . 34858457) (answer_id . 34858538) (creation_date . 1453131440) (last_activity_date . 1453131440) (score . 5) (is_accepted) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/440558/joachim-pileborg") (display_name . "Joachim Pileborg") (profile_image . "https://i.stack.imgur.com/9ZYta.jpg?s=128&g=1") (accept_rate . 75) (user_type . "registered") (user_id . 440558) (reputation . 177029))) ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858568#34858568") (body_markdown . "The move constructor is not implicitly declared, because you have a user-declared destructor (see [[class.copy]/(9.4)][1]). However, the copy constructor is clearly deleted, since `unique_ptr` can't be copied.\n\nYou can explicitly declare the move constructor as defaulted.\n\n\n [1]: http://eel.is/c++draft/class.copy#9") (share_link . "http://stackoverflow.com/a/34858568/692055") (question_id . 34858457) (answer_id . 34858568) (creation_date . 1453131565) (last_activity_date . 1453131565) (score . 10) (is_accepted . t) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/3647361/columbo") (display_name . "Columbo") (profile_image . "https://i.stack.imgur.com/xvjhM.png?s=128&g=1") (accept_rate . 83) (user_type . "registered") (user_id . 3647361) (reputation . 35995)))) (tags "c++" "c++11" "visual-c++" "visual-studio-2015" "move-semantics")) focus)
sx-display(((title . "Why can't I declare a variable using auto?") (site_par . "stackoverflow") (link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto") (body_markdown . "I'm getting a compile error in Visual Studio 2015 when I try to declare a variable of class, when that classes uses the PIMPL pattern.\n\nFoo.h:\n\n #pragma once\n\n class Foo\n {\n public:\n Foo(const std::wstring& str,\n const std::vector<std::wstring>& items);\n ~Foo();\n\n private:\n struct Impl;\n std::unique_ptr<Impl> pimpl;\n };\n\nFoo.cpp:\n\n #include \"stdafx.h\"\n #include \"Foo.h\"\n\n struct Foo::Impl\n {\n public:\n Impl(const std::wstring& str,\n const std::vector<std::wstring>& items);\n\n std::wstring str_;\n std::vector<std::wstring> items_;\n };\n\n Foo::Foo(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : pimpl(std::make_unique<Impl>(str, items))\n {\n }\n\n Foo::~Foo() = default;\n\n Foo::Impl::Impl(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : str_(str),\n items_(items)\n {\n }\n\nIf I declare a variable of type `Foo` using the traditional syntax, it compiles fine:\n\n Foo f(L\"Hello\", std::vector<std::wstring>());\n\nHowever, if I declare it using `auto`, then I get a compile error:\n\n auto f2 = Foo { L\"Goodbye\", std::vector<std::wstring>() };\n\n> error C2280: 'Foo::Foo(const Foo &)': attempting to reference a deleted function \n> note: compiler has generated 'Foo::Foo' here\n\nI understand that the copy constructor for `Foo` should be deleted, since `unique_ptr` can't be copied. However, it was my understanding that when declaring variables in this way, the result would be either moved into the variable or just set the value into the variable directly.\n\nThe second line compiles fine when using Visual Studio 2013. I checked the breaking changes in Visual Studio 2015, but I didn't see anything there that would indicate why this started failing.\n\nAm I doing something wrong, or can this syntax not be used with non-copyable types?") (share_link . "http://stackoverflow.com/q/34858457/692055") (question_id . 34858457) (last_edit_date . 1453131941) (creation_date . 1453131263) (last_activity_date . 1453131941) (score . 4) (answer_count . 2) (accepted_answer_id . 34858568) (view_count . 187) (is_answered . t) (upvoted) (downvoted) (last_editor (link . "http://stackoverflow.com/users/636019/ildjarn") (display_name . "ildjarn") (profile_image . "https://www.gravatar.com/avatar/38ba39c7ba510ac2951c010c26afb6a6?s=128&d=identicon&r=PG") (user_type . "registered") (user_id . 636019) (reputation . 42901)) (owner (link . "http://stackoverflow.com/users/3857/andy") (display_name . "Andy") (profile_image . "https://www.gravatar.com/avatar/21599de27f8bc6cc7e9b3d002addbca8?s=128&d=identicon&r=PG") (accept_rate . 100) (user_type . "registered") (user_id . 3857) (reputation . 18755)) (answers ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858538#34858538") (body_markdown . "Because the class contains a [`std::unique_ptr`](http://en.cppreference.com/w/cpp/memory/unique_ptr) member the compiler can't generate a copy-constructor like it would normally do, which means your declaration and initialization (which invokes the copy-constructor) will not be possible.\n\nYou could solve it by making a [move constructor](http://en.cppreference.com/w/cpp/language/move_constructor) for your class and mark it as `default`.") (share_link . "http://stackoverflow.com/a/34858538/692055") (question_id . 34858457) (answer_id . 34858538) (creation_date . 1453131440) (last_activity_date . 1453131440) (score . 5) (is_accepted) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/440558/joachim-pileborg") (display_name . "Joachim Pileborg") (profile_image . "https://i.stack.imgur.com/9ZYta.jpg?s=128&g=1") (accept_rate . 75) (user_type . "registered") (user_id . 440558) (reputation . 177029))) ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858568#34858568") (body_markdown . "The move constructor is not implicitly declared, because you have a user-declared destructor (see [[class.copy]/(9.4)][1]). However, the copy constructor is clearly deleted, since `unique_ptr` can't be copied.\n\nYou can explicitly declare the move constructor as defaulted.\n\n\n [1]: http://eel.is/c++draft/class.copy#9") (share_link . "http://stackoverflow.com/a/34858568/692055") (question_id . 34858457) (answer_id . 34858568) (creation_date . 1453131565) (last_activity_date . 1453131565) (score . 10) (is_accepted . t) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/3647361/columbo") (display_name . "Columbo") (profile_image . "https://i.stack.imgur.com/xvjhM.png?s=128&g=1") (accept_rate . 83) (user_type . "registered") (user_id . 3647361) (reputation . 35995)))) (tags "c++" "c++11" "visual-c++" "visual-studio-2015" "move-semantics")))
funcall-interactively(sx-display ((title . "Why can't I declare a variable using auto?") (site_par . "stackoverflow") (link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto") (body_markdown . "I'm getting a compile error in Visual Studio 2015 when I try to declare a variable of class, when that classes uses the PIMPL pattern.\n\nFoo.h:\n\n #pragma once\n\n class Foo\n {\n public:\n Foo(const std::wstring& str,\n const std::vector<std::wstring>& items);\n ~Foo();\n\n private:\n struct Impl;\n std::unique_ptr<Impl> pimpl;\n };\n\nFoo.cpp:\n\n #include \"stdafx.h\"\n #include \"Foo.h\"\n\n struct Foo::Impl\n {\n public:\n Impl(const std::wstring& str,\n const std::vector<std::wstring>& items);\n\n std::wstring str_;\n std::vector<std::wstring> items_;\n };\n\n Foo::Foo(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : pimpl(std::make_unique<Impl>(str, items))\n {\n }\n\n Foo::~Foo() = default;\n\n Foo::Impl::Impl(const std::wstring& str,\n const std::vector<std::wstring>& items)\n : str_(str),\n items_(items)\n {\n }\n\nIf I declare a variable of type `Foo` using the traditional syntax, it compiles fine:\n\n Foo f(L\"Hello\", std::vector<std::wstring>());\n\nHowever, if I declare it using `auto`, then I get a compile error:\n\n auto f2 = Foo { L\"Goodbye\", std::vector<std::wstring>() };\n\n> error C2280: 'Foo::Foo(const Foo &)': attempting to reference a deleted function \n> note: compiler has generated 'Foo::Foo' here\n\nI understand that the copy constructor for `Foo` should be deleted, since `unique_ptr` can't be copied. However, it was my understanding that when declaring variables in this way, the result would be either moved into the variable or just set the value into the variable directly.\n\nThe second line compiles fine when using Visual Studio 2013. I checked the breaking changes in Visual Studio 2015, but I didn't see anything there that would indicate why this started failing.\n\nAm I doing something wrong, or can this syntax not be used with non-copyable types?") (share_link . "http://stackoverflow.com/q/34858457/692055") (question_id . 34858457) (last_edit_date . 1453131941) (creation_date . 1453131263) (last_activity_date . 1453131941) (score . 4) (answer_count . 2) (accepted_answer_id . 34858568) (view_count . 187) (is_answered . t) (upvoted) (downvoted) (last_editor (link . "http://stackoverflow.com/users/636019/ildjarn") (display_name . "ildjarn") (profile_image . "https://www.gravatar.com/avatar/38ba39c7ba510ac2951c010c26afb6a6?s=128&d=identicon&r=PG") (user_type . "registered") (user_id . 636019) (reputation . 42901)) (owner (link . "http://stackoverflow.com/users/3857/andy") (display_name . "Andy") (profile_image . "https://www.gravatar.com/avatar/21599de27f8bc6cc7e9b3d002addbca8?s=128&d=identicon&r=PG") (accept_rate . 100) (user_type . "registered") (user_id . 3857) (reputation . 18755)) (answers ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858538#34858538") (body_markdown . "Because the class contains a [`std::unique_ptr`](http://en.cppreference.com/w/cpp/memory/unique_ptr) member the compiler can't generate a copy-constructor like it would normally do, which means your declaration and initialization (which invokes the copy-constructor) will not be possible.\n\nYou could solve it by making a [move constructor](http://en.cppreference.com/w/cpp/language/move_constructor) for your class and mark it as `default`.") (share_link . "http://stackoverflow.com/a/34858538/692055") (question_id . 34858457) (answer_id . 34858538) (creation_date . 1453131440) (last_activity_date . 1453131440) (score . 5) (is_accepted) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/440558/joachim-pileborg") (display_name . "Joachim Pileborg") (profile_image . "https://i.stack.imgur.com/9ZYta.jpg?s=128&g=1") (accept_rate . 75) (user_type . "registered") (user_id . 440558) (reputation . 177029))) ((link . "http://stackoverflow.com/questions/34858457/why-cant-i-declare-a-variable-using-auto/34858568#34858568") (body_markdown . "The move constructor is not implicitly declared, because you have a user-declared destructor (see [[class.copy]/(9.4)][1]). However, the copy constructor is clearly deleted, since `unique_ptr` can't be copied.\n\nYou can explicitly declare the move constructor as defaulted.\n\n\n [1]: http://eel.is/c++draft/class.copy#9") (share_link . "http://stackoverflow.com/a/34858568/692055") (question_id . 34858457) (answer_id . 34858568) (creation_date . 1453131565) (last_activity_date . 1453131565) (score . 10) (is_accepted . t) (upvoted) (downvoted) (owner (link . "http://stackoverflow.com/users/3647361/columbo") (display_name . "Columbo") (profile_image . "https://i.stack.imgur.com/xvjhM.png?s=128&g=1") (accept_rate . 83) (user_type . "registered") (user_id . 3647361) (reputation . 35995)))) (tags "c++" "c++11" "visual-c++" "visual-studio-2015" "move-semantics")))
call-interactively(sx-display nil nil)
command-execute(sx-display)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment