errors C3853, C2440, C2678
very simple demo:
//------------
#include <string>
#include <map>
using namespace std;
struct C {
long id;
C() : id(0) {}
C(const long Id) : id(Id) {}
};
int main(int argc, char *argv[])
{
map<string, C> cc;
cc["first"] = C(1);
for(map<string, C>::iterator it = cc.begin(); it != cc.end(); ++it)
cout << it->second.id << endl;
return 0;
}
//------------
everything goes fine, and no question appears. but problems start to happen,
when i use a template, like:
//------------
#include <string>
#include <map>
using namespace std;
template<class T>
struct tC {
map<string, typename(T)> cc;
};
struct C {
long id;
C() : id(0) {}
C(const long Id) : id(Id) {}
};
int main(int argc, char *argv[])
{
tC<C> c;
c.cc["first"] = C(1); // error C3853: '=': re-initializing a reference or
assignment through a reference-to-function is illegal
// error C2440: '=' : cannot convert from 'C' to 'int (__cdecl &)(T)'
for(map<string, C>::iterator it = c.cc.begin(); it != c.cc.end(); ++it)
// error C2440: 'initializing' : cannot convert from
'std::_Tree<_Traits>::iterator' to 'std::_Tree<_Traits>::iterator'
// error C2678: binary '!=' : no operator found which takes a
left-hand operand of type 'std::_Tree<_Traits>::iterator' (or there is no
acceptable conversion)
cout << it->second.id << endl;
return 0;
}
//------------
what did i do wrong? i don't get those error messages. especially why may
not i convert from 'std::_Tree<_Traits>::iterator' to
'std::_Tree<_Traits>::iterator'?
***
MS Studio 2005, SP1 used. VS++ 8.0.50727.762 (SP.050727-7600)
--
alex c.