Error in creating map iterator

Hi

Dear all

Kindly can you help me to solve the error in creating map iterator.

.h , .cpp and error list are attached. I found there is error in creating map iterator (error C2374: 'map_Iter' : redefinition; multiple initialization ).

First of all there is no other definition of map_Iter also i tried to solve by different names and ways but nothing. So, please guide me

Thanks in advance.


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
Header file

#include <pl.h>
#include <vector>
#include "commonTypes.h"
#include "cond_indep/indepTest.h"
#include <map>

typedef plDataDescriptor<slMyRowDataType> slDataSet;

using namespace std;

struct resultBackup
{
        bool test;
	double chiValue, pValue;
};


static std::map<string, resultBackup> testValuesCashe;


class computeChiSquare: public chiSequare
{

	
public:
	/**! Constructor. **/
	computeChiSquare(slDataSet * const _pCompDataSet, plVariablesConjunction *_variables = 0,
		float *_alpha = 0, double *_chi2 = 0, double *_p = 0);

// 	/**! Run the chi2 test. **/
    bool chi_square_test(int, int, std::vector <int>);
 
	   
protected:


};

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
CPP file

#include <iostream>
#include "ComputeChiSquare.h"


using namespace std;

computeChiSquare::computeChiSquare(slDataSet * const _pCompDataSet, plVariablesConjunction *_variables, 
								   float *_alpha, double *_chi2, double *_p):chiSequare(_pCompDataSet, _variables, _alpha, _chi2, _p)
{

}

bool computeChiSquare::chi_square_test(int a, int b, std::vector<int> cond_vars)
{

	// Put variables in a vector then sort them
	std::vector<int> varAB;
	varAB.push_back(a); varAB.push_back(b);
	sort(varAB.begin(), varAB.end());
	sort(cond_vars.begin(), cond_vars.end());

	// Generate a string by variables names and conditional variables like v121234
	stringstream varNames;
	varNames <<"v";
	for (int i = 0; i < varAB.size(); i++)
	{
		varNames <<varAB[i];
	}
	for (int i = 0; i < cond_vars.size(); i++)
	{
		varNames <<cond_vars[i];
	}
	cout<<"\n var names as a string = "<< varNames.str();

	// Find whether test already calculated.
	std::map <string, resultBackup>::iterator map_Iter,
		
	map_Iter = testValuesCashe.find(varNames.str());

	bool test = false;
	resultBackup testResult; // to store the chi2 values

	if (map_Iter == testValuesCashe.end())
	{
		test = chiSequare::chi_square_test(a, b, cond_vars);

		testResult.test = test;
		testResult.chiValue= chiSequare::getChi2();
		testResult.pValue = chiSequare::getPValue();
		testValuesCashe.insert(make_pair(varNames.str(), testResult));

	}
	else
	{
		test = map_Iter->second.test;
		chiSequare::chi2 = map_Iter->second.chiValue;
		chiSequare::p = map_Iter->second.pValue ;
	    cout<<"\n chi = "<<map_Iter->second.chiValue <<" p value ="<<map_Iter->second.pValue;
		cout<<"\n ------------------ test already computed";
		
	}

return test;	

}


errors


1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(61) : error C2374: 'map_Iter' : redefinition; multiple initialization
1>        c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(59) : see declaration of 'map_Iter'
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(66) : error C2088: '==' : illegal for class
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(78) : error C2065: 'map_Iter1' : undeclared identifier
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(78) : error C2227: left of '->second' must point to class/struct/union/generic type
1>        type is ''unknown-type''
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(78) : error C2228: left of '.test' must have class/struct/union
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(79) : error C2039: 'second' : is not a member of 'std::_Tree<_Traits>::iterator'
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,resultBackup,std::less<std::string>,std::allocator<std::pair<const std::string,resultBackup>>,false>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(412) : see declaration of 'std::_Tree<_Traits>::iterator'
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,resultBackup,std::less<std::string>,std::allocator<std::pair<const std::string,resultBackup>>,false>
1>        ]
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(79) : error C2228: left of '.chiValue' must have class/struct/union
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(80) : error C2039: 'second' : is not a member of 'std::_Tree<_Traits>::iterator'
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,resultBackup,std::less<std::string>,std::allocator<std::pair<const std::string,resultBackup>>,false>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(412) : see declaration of 'std::_Tree<_Traits>::iterator'
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,resultBackup,std::less<std::string>,std::allocator<std::pair<const std::string,resultBackup>>,false>
1>        ]
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(80) : error C2228: left of '.pValue' must have class/struct/union
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(81) : error C2039: 'second' : is not a member of 'std::_Tree<_Traits>::iterator'
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,resultBackup,std::less<std::string>,std::allocator<std::pair<const std::string,resultBackup>>,false>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(412) : see declaration of 'std::_Tree<_Traits>::iterator'
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,resultBackup,std::less<std::string>,std::allocator<std::pair<const std::string,resultBackup>>,false>
1>        ]
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(81) : error C2228: left of '.chiValue' must have class/struct/union
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(81) : error C2039: 'second' : is not a member of 'std::_Tree<_Traits>::iterator'
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,resultBackup,std::less<std::string>,std::allocator<std::pair<const std::string,resultBackup>>,false>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(412) : see declaration of 'std::_Tree<_Traits>::iterator'
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,resultBackup,std::less<std::string>,std::allocator<std::pair<const std::string,resultBackup>>,false>
1>        ]
1>c:\probt_slp_2.1\trunk_probt21\work\yasin\testmmhc\testmmhc\mmhc\computechisquare.cpp(81) : error C2228: left of '.pValue' must have class/struct/union



Last edited on
I believe you want a semi-colon at the end of line 38 of your .cpp file.

std::map <string, resultBackup>::iterator map_Iter,
Last edited on
yes of course,

thank you,
Topic archived. No new replies allowed.