Migrating code from VS2008 to VS2010: Error C3892

All,
I'm still converting code from Visual Stusio 2008 to version 2010 but ...


Error C3892:
"std::_Tree_unchecked_const_iterator<_Mytree,_Base>::operator ->":

<CODE>
#include <set>

for(SubType::iterator i=tmp.sub.begin();i!=tmp.sub.end();++i){
if(i->streaming){
if(fGlobalStreaming||!i->updated){
TFormula* f=i->f;
f->Set(i->o,tmp.xl);
i->updated=true;
}
}else{
if(!i->updated){
i->f->Set(i->o,tmp.xl);
i->updated=true;
}
}
}
</CODE>

I understood that I have to avoid changing values of const items, not a prob. But there is no const item.
I found that std::set is always provoking const values. But how to avoid this? I'm in need of this include for the rest f the code ...

Any hint much appreciated,
surplus
Last edited on
You'll have to redesign. An std::set doesn't allow its elements to be modified in any way because it doesn't understand the comparison function. If you modify a member of the object and this modification alters the order of the object within the collection, this leaves the set in an inconsistent state.

You could change the std::set<V> into an std::map<K, V>, where there exists a function K f(V) such that a < b if and only if f(a) < f(b). If you post the definition of your class and your comparison function maybe we can figure something out.
But there is no const item.

Yes there is a const item because all iterators in a set point to constant elements.
But how to avoid this?

Basically you can't. If you must alter an element perhaps you shouldn't be using a set.

The only work around, that I'm aware of, would be to remove the element, then insert the modified element.
closed account (48T7M4Gy)
http://www.cplusplus.com/reference/set/set/operators/
Thx for all the reply!!
Give me a minute I got to study and understand ...


/surplus
@helios
thx for your offer. I try to post the necessary.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <map>
#include <set>
#include <deque>
#include <string>
#include "Linear_Alloc.h"
#include "independent.h"
#include "Synchro.h"
#include "CustomData.h"
#include "ConfigClass.h"
#include <windows.h>

        template< typename T >
	int Update(const T& cd){
		ALock vLock(fLock);
		const c_wstring& sName = cd.GetName();
		TFieldKeyType fName;

		int cnt=0;
		typename T::Fields::const_iterator vBegin = cd.GetFields().begin(), vEnd = cd.GetFields().end();

		Symbols::iterator i=buffer.find(sName);
		if(i==buffer.end())return cnt;
		if(cd.GetId())
			i->second.ID=cd.GetId();
		Fields& fields=i->second.fields;
		if(i->second.ID<0){
			Fields& fields=i->second.fields;
			for(Fields::iterator field=fields.begin();field!=fields.end();++field){
				FieldStruct& tmp=field->second;
				for(SubType::iterator FS_iter=tmp.sub.begin();FS_iter!=tmp.sub.end();++FS_iter){
					FS_iter->f->Set(FS_iter->o,tmp.xl=GetErrText(i->second.ID));
					FS_iter->f->SnapReady(sName);
				}
			}
			fields.clear();
			return cnt;
		}
		while(vBegin!=vEnd){
			fName=vBegin->GetId();
			Fields::iterator field=fields.find(fName);
			if(field!=fields.end()){
				FieldStruct& tmp=field->second;
				switch(vBegin->GetType()){
					case ConfigField::FIELD_TYPE_INT:
						tmp.xl=vBegin->GetInt();
						break;
					case ConfigField::FIELD_TYPE_PRICE:
						tmp.xl=vBegin->GetDouble();
						break;
					case ConfigField::FIELD_TYPE_TIME:
					case ConfigField::FIELD_TYPE_TIME_S:
						TimeParser(tmp.xl,vBegin->GetString());
						break;
					case ConfigField::FIELD_TYPE_DATE:
						DateParser(tmp.xl,vBegin->GetString());
						break;
					default:
						tmp.xl= vBegin->GetString();
						break;
				}

				for(SubType::iterator i=tmp.sub.begin();i!=tmp.sub.end();++i){
					if(i->streaming){
						if(fGlobalStreaming||!i->updated){
							TFormula* f=i->f;
							f->Set(i->o,tmp.xl);
							i->updated=true;
						}
					}else{
						if(!i->updated){
							i->f->Set(i->o,tmp.xl);
							i->updated=true;
						}
					}
				}

				cnt++;
				++vBegin;
			}else{
				cnt++;
				++vBegin;
			}
		}
		if(cd.GetCode()==340){
			for(Fields::iterator field=fields.begin();field!=fields.end();++field){
				FieldStruct& tmp=field->second;
				const static CPP_XLOPER xlDefault;
				if(tmp.xl.xltype==xlDefault.xltype){
					for(SubType::iterator sub_iter=tmp.sub.begin();sub_iter!=tmp.sub.end();++sub_iter){
						TFormula* f=sub_iter->f;
						f->Set(sub_iter->o,tmp.xl=xErrNoFID);
					}
				}
			}
			i->second.snapshot_ready=true;
			for(Fields::iterator field=fields.begin();field!=fields.end();++field){
				FieldStruct& tmp=field->second;
				for(SubType::iterator sub_iter=tmp.sub.begin();sub_iter!=tmp.sub.end();++sub_iter){
					TFormula* f=sub_iter->f;
					f->SnapReady(sName);
				}
			}
		}
	return cnt;
	}


If my information is not sufficient enough pls come back. I'm not that pro on C++.


Regards
surplus

P.S.: There is weekend in Munich in 2 h ... (May I write you a PM probably on Monday?)
You only posted the code that causes the error. I need to see the type that the std::set contains and the comparison function.
Hi helios,
thx for your help.

The comparison function which causes the error is:

hpp
<code>
void TransferSymbolToVB(const Symbol&);
</code>

cpp
<code>
void ServerAdapter::TransferSymbolToVB(const Symbol& symbol) {
valueBuffer_->Update(symbol);
}

</code>


Pls tell me if there is something else I can do.

Thx in advance
surplus

Topic archived. No new replies allowed.