Original Post
It's hard to explain what I want exactly, so I'll start with an example. The second argument in boost::shared_ptr's constructor is an object that will be used to delete the internal pointer. When creating a boost::shared_ptr, you don't have to specify it's type as an additional template parameter. For example: My question is - how do I specify the type of 't'? I tried to figure out how boost does it, but quickly got lost in the code. Is there a simple solution? Thanks in advance.
SDL_Surface *s = SDL_LoadBMP("image.bmp");
boost::shared_ptr<SDL_Surface> sp(s, SDL_LoadSurface);
In the code above, you don't have to specify the type of SDL_LoadSurface, that is, you don't write: boost::shared_ptr<SDL_Surface, void (*)()> sp(s, SDL_LoadSurface); I am trying to do something similar, but I have one problem which the following code clearly demonstrates:
class A {
public:
template <class T>
A(T tt):t(tt) {}
void func() {
t(17);
}
private:
??? t;
};
// Example usage:
struct Obj {
void operator()(int i) {
// ...
}
};
void func() {
A a(Obj());
}