constness being applied implicitly?

I've got an application that is compiled in VS 2010 using both the vc9 tool set and vc10 tool set. In vc9 the solution compiles with no warnings or errors. In vc10 I am getting the following error:

 
error C2440: 'return' : cannot convert from 'const Observer::Topic::Transport' to 'Observer::Topic::Transport &'


One thing to note is that the convert from is showing as an object and not a reference, which is strange because the return value of the function being called returns a reference. Anyhow, this is all taking place in the non const overloaded [] operator as such:


Note: "this" is non const
m_transports is a member of "this"
Get() returns a reference to Transport, has a const and non const overload
1
2
3
4
5
6
7
8
9
inline Transport& TransportContainer::operator [](const std::string& keyval)
{
	VTransport search(keyval);
	SetVTransport::iterator it = m_transports->find(search);
	if(it != m_transports->end())
		return const_cast<VTransport &>(*it).Get(); //This is how I have to cast it to not get the error...
	std::pair<SetVTransport::iterator, bool> ret = m_transports->insert(type); //This is here for debugging
	return /*const_cast<VMICDataType &>*/(*ret.first).Get();//This gives me the compile error, if I uncomment out the cast it works fine.
}

This function is supposed to return the element at the index or add the new element so that the container functions like std::map operator[]

Throughout the code, in vc10 it's as if any calls to std::map.find() returns a const_iterator.

The VTransport is a Template class used for memory management, the set contains these as elements. The set is declared with a comparison function. I thought maybe since they were const it was const qualifying the return values. I added non const's just to be sure and this changed nothing.

The call sites "appear" to be non const, I have not verified, I'm going to step through the debugger now in vc9 and vc10 and report back.

The code works if I use the const casts but it looks ugly, it may just be that the older toolset does not care and that the const casts are there for a reason, or I've missed an implementation somewhere or called something using an incorrect qualifier.

Thanks.
Last edited on
The keys in a map are constant because the map could become invalid if a key changed.
Last edited on
This is exactly what my problem is, I have to cast, thank you!I need to slap myself for not thinking of this.
Topic archived. No new replies allowed.