I want to make functor to generic function, but I get compiler error.
Here is the code:
template <class T>
struct Creator
{
template <typename...Ts>
static std::shared_ptr<T> create(Ts&&... vs)
{
std::shared_ptr<T> t(new T(std::forward<Ts>(vs)...));
return t;
}
};
class Car:
public Creator<Car>
{
private:
friend class Creator<Car>;
Car()
{
}
};
int main()
{
auto car=Car::create();
std::function< std::shared_ptr<Car> () > createFn=&Car::create;
return 0;
}
I get the following error in GCC 4.6.3 on the second statement(the first is OK):
error: conversion from ‘<unresolved overloaded function type>’
to non-scalar type ‘std::function<std::shared_ptr<Car>()>’ requested
Any hint appreciated.
If the pointer of a template function is needed, the template must be instantiated first.
This will make it compile on clang++ 3.1, but g++ 4.8 still refuses to compile, which I believe is a bug.
You could provide a lambda function instead: