Я пытаюсь создать словарь свойств, которые считываются из сцены XML блендера, и столкнулся с проблемой с шаблонами и получением их type_info. Содержащая карта настраивается как имя свойства и его значение, которое хранится в структуре typeinfo и union. Возможно ли это сделать таким образом или он должен распознавать его по указанному типу c? Я предпринял попытки инициализировать структуру перед передачей ее на карту и даже скопировать двоичные данные в объединение, но каждый раз при получении typeid (T) возникают ошибки. И я также попытался использовать кортежи на карте вместо структуры. Вот строка, вызывающая ошибку
line 80 = mProperties[name] = std::make_tuple(typeid(T), d);
Ошибка
Severity Code Description Project File Line Suppression State
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'std::tuple<type_info,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>' (or there is no acceptable conversion) OgreEngine D:\SchoolAndProjects\Programs\ETGG 3802_01 Realtime Interactive Prog 2\Lab 1\OgreEngine\OgreEngine\include\component.h 80
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'std::tuple<type_info,int>' (or there is no acceptable conversion) OgreEngine D:\SchoolAndProjects\Programs\ETGG 3802_01 Realtime Interactive Prog 2\Lab 1\OgreEngine\OgreEngine\include\component.h 80
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'std::tuple<type_info,float>' (or there is no acceptable conversion) OgreEngine D:\SchoolAndProjects\Programs\ETGG 3802_01 Realtime Interactive Prog 2\Lab 1\OgreEngine\OgreEngine\include\component.h 80
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'std::tuple<type_info,double>' (or there is no acceptable conversion) OgreEngine D:\SchoolAndProjects\Programs\ETGG 3802_01 Realtime Interactive Prog 2\Lab 1\OgreEngine\OgreEngine\include\component.h 80
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'std::tuple<type_info,bool>' (or there is no acceptable conversion) OgreEngine D:\SchoolAndProjects\Programs\ETGG 3802_01 Realtime Interactive Prog 2\Lab 1\OgreEngine\OgreEngine\include\component.h 80
Error C2280 'void *std::pair<const std::string,std::tuple<type_info,OgreEngine::Component::data>>::__delDtor(unsigned int)': attempting to reference a deleted function OgreEngine C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\xmemory 676
Error C2280 'void *std::pair<const std::string,std::tuple<type_info,OgreEngine::Component::data>>::__delDtor(unsigned int)': attempting to reference a deleted function OgreEngine C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\xmemory 676
Error C2280 'void *std::pair<const std::string,std::tuple<type_info,OgreEngine::Component::data>>::__delDtor(unsigned int)': attempting to reference a deleted function OgreEngine C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\xmemory 676
Error C2280 'void *std::pair<const std::string,std::tuple<type_info,OgreEngine::Component::data>>::__delDtor(unsigned int)': attempting to reference a deleted function OgreEngine C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\xmemory 676
Error C2280 'void *std::pair<const std::string,std::tuple<type_info,OgreEngine::Component::data>>::__delDtor(unsigned int)': attempting to reference a deleted function OgreEngine C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\xmemory 676
Код:
private:
union data
{
std::string sVal;
bool bVal;
int iVal;
float fVal;
double dVal;
};
struct propertyData {
type_info dataType;
data val;
};
protected:
GameObject* Parent;
std::map<std::string, std::tuple<type_info, data>> mProperties;
public:
/// Append the property of type T to the property map container
template<typename T>
void add_xml_property(std::string name, T d)
{
if (mProperties.find(name) == mProperties.end())
{
//struct propertyData pData = {typeid(T), d};
//memcpy_s((void*)&pData.val, sizeof(d), (void*)&d, sizeof(d));
mProperties[name] = std::make_tuple(typeid(T), d);
}
};