Skip to main content
gamedev.net
🔒 Locked

template error

Started by Freaker13 2 replies 350+ views
Original Post
Freaker13
Freaker13
hi all, I get the folowing error when i use this templated function
template<class T> T getSetting(std::string name)
{
  return toVal(settingMap[name]);
}
error C2783: ''T __thiscall cSettingsManager::getSetting(class _STL::basic_string,class _STL::allocator >)'' : could not deduce template argument fo r ''T'' i use the function like this:
int a = cSettingsManager::getSingleton().getSetting("test");
i v'' also tried to do this:
int a = cSettingsManager::getSingleton()<int>.getSetting("test");
but then i get this error: error C2062: type ''int'' unexpected thx in advance
Bobo_the_Programmer
Bobo_the_Programmer
The compiler cannot deduce template type parameters when it is dependent upon the return type. You have to explicitly specialize it. You just put the specialization in the wrong spot:

int a = cSettingsManager::getSingleton().getSetting("test");
Freaker13
Freaker13
No according to an article on the internet it''s an error in the vs6.0 compiler. the solution is to use an dummy argument.not nice but better than nothing
Aprosenf
Aprosenf
The following will work. Note that the <int> is to the right of the function name but before the opening parenthesis.

int a = cSettingsManager::getSingleton().getSetting<int>("test") ;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.