Skip to content

Instantly share code, notes, and snippets.

@hisui
Created December 10, 2012 20:40
Show Gist options
  • Save hisui/4253215 to your computer and use it in GitHub Desktop.
Save hisui/4253215 to your computer and use it in GitHub Desktop.
なんでエラー?
// 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