I have this really annoying error I can't fix. Spend hours trying to find a solution, nothing yet. I've tried using a handful of methods to fix it, but nothing has worked. Here's what I've tried:
original:
std::unique_ptr<T, void(*)(void*)> p( resource, delete_func );
m_map[id] = std::move(p);
2nd attempt:
m_map.emplace( 1, std::unique_ptr<T, void(*)(void*)>( resource, delete_func ) );
3rd attempt:
m_map.insert( std::unordered_map<uint64_t, std::unique_ptr<T, void(*)(void*)>>::value_type( 1, std::unique_ptr<T, void(*)(void*)>( resource, delete_func ) ) );
I end up with the same error every time! What is going on here? Here's the full definition of my class:
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <memory>
#include "str_id.hpp"
/*
* Resource management class
*/
template <class T>
class resource_manager_t
{
public:
resource_manager_t() {};
virtual ~resource_manager_t() {};
public:
void add_resource( char* resource_id, T* resource, void (*delete_func)(void*) )
{
/* Add this resource to the list */
m_strids.add_cstr( resource_id );
uint64_t id = m_strids.get_cstr_id( resource_id );
m_map.insert( std::unordered_map<uint64_t, std::unique_ptr<T, void(*)(void*)>>::value_type( 1, std::unique_ptr<T, void(*)(void*)>( resource, delete_func ) ) );
}
T* get_resource( char* resource_id )
{
uint64_t id = m_strids.get_cstr_id( resource_id );
if( id != 0 )
{
return m_map[id].get();
}
return nullptr;
}
private:
std::unordered_map<uint64_t, std::unique_ptr<T, void(*)(void*)>> m_map;
cstr_id_manager_t m_strids;
};
At this point I'm completely out of ideas. This sucks. Anyone else have any ideas? Thanks.
Shogun.
EDIT: The title of this thread is the error message I'm getting, but if the more detailed version of it helps, here it is:
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(1347): error C2338: unique_ptr constructed with null deleter pointer
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(1343) : while compiling class template member function 'std::unique_ptr<T,void (__cdecl *)(void *)>::unique_ptr(void) throw()'
1> with
1> [
1> T=int
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(746) : see reference to function template instantiation 'std::unique_ptr<T,void (__cdecl *)(void *)>::unique_ptr(void) throw()' being compiled
1> with
1> [
1> T=int
1> ]
1> c:\shogun3d\kaho\source\resource_manager.h(29) : see reference to class template instantiation 'std::unique_ptr<T,void (__cdecl *)(void *)>' being compiled
1> with
1> [
1> T=int
1> ]
1> c:\shogun3d\kaho\source\resource_manager.h(22) : while compiling class template member function 'void resource_manager_t<int>::add_resource(char *,T *,void (__cdecl *)(void *))'
1> with
1> [
1> T=int
1> ]
1> c:\shogun3d\kaho\source\game.cpp(19) : see reference to function template instantiation 'void resource_manager_t<int>::add_resource(char *,T *,void (__cdecl *)(void *))' being compiled
1> with
1> [
1> T=int
1> ]
1> c:\shogun3d\kaho\source\game.cpp(16) : see reference to class template instantiation 'resource_manager_t<int>' being compiled