Created
December 10, 2012 20:40
-
-
Save hisui/4253215 to your computer and use it in GitHub Desktop.
なんでエラー?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) | |
#include <iostream> | |
#include <memory> | |
struct hoge_0 | |
{ | |
virtual void call() = 0; | |
}; | |
template<typename Func> | |
std::shared_ptr<hoge_0> make_hoge(const Func &func) | |
{ | |
struct hoge: hoge_0 | |
{ | |
Func func; | |
hoge(const Func &func) | |
:func(func) | |
{ | |
} | |
void call() | |
{ | |
(this->func)(); | |
} | |
}; | |
// OK: return std::shared_ptr<hoge>(new hoge(func)); | |
return std::make_shared<hoge>(func); // error: no matching constructor for initialization of 'hoge' | |
} | |
int main() | |
{ | |
auto hoge = make_hoge([] () { std::cerr << "hi!" << std::endl; }); | |
hoge->call(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment