Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

Access template class parameter from lambda

$
0
0

I'm writing a simple universal pool. The template class takes a parameter in the constructor that is a factory function to instantiate objects in the pool as needed

template <typename T>
class LIFOPool
{
    std::function <T*()> factory_;
    //...details irrelevant
public:
    LIFOPool(std::function<T*()> factory) : factory_(factory) {}
    //...details irrelevant
};

This compiles fine, but I wanted to make a default argument for the constructor using lambda:

LIFOPool(std::function<T*()> factory = [](){return new T();} ) : factory_(factory) {}

It gives me error C2061: syntax error : identifier 'T'.

Now this compiles fine with gcc4.8. Is there a way to make lambdas aware of template parameters in VC13?


Viewing all articles
Browse latest Browse all 21115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>