Pb Code::Blocks et Map, find
Bonsoir,
je ne comprend pas pourquoi ce code ne fonctionne pas. En fait, si le code du fichier .h et .cpp sont placés dans un fichier .cpp au dessus du main alors tout fonctionne. Je suis sous Code::Blocks8.02 mingw.
Jamais, la valeur de l'élément dont la clé est "C" ne sera mis à jour.
Par contre, si l'ensemble de ce code est mis dans un seul fichier, alors cela fonctionne.
En vous remerciant pour vos conseils,
Bonne soirée.
Xavier
fichier EnthalpyData.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
// ====================================================
// Enthalpy Data
// Class which manage all the necessary data
// ====================================================
#ifndef __ENTHALPYDATA_H__
#define __ENTHALPYDATA_H__
#include <map>
class GsmAnalysis1
{
public:
GsmAnalysis1();
~GsmAnalysis1();
void setCompoundByName(const char* compound, double valCompound);
private:
std::map<const char*, double> _analysisMap;
};
#endif // __ENTHALPYDATA_H__ |
fichier Enthalpy.cpp
Code:
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
|
// ====================================================
// GSMEnthalpy Data
// Class which manage all the necessary data
// ====================================================
#include "GSMEnthalpyData.h"
#include <iostream>
using namespace std;
GsmAnalysis1::GsmAnalysis1()
{
_analysisMap["C"] = 4.0;
}
GsmAnalysis1::~GsmAnalysis1()
{
}
void
GsmAnalysis1::setCompoundByName(const char* compound, double valCompound)
{
std::map<const char*, double>::iterator it;
it=_analysisMap.find(compound);
if (it == _analysisMap.end())
cout << "It not found" << endl;
else
{
cout << "It: " << it->first << " ==> " << it->second << endl;
_analysisMap.erase (compound);
_analysisMap[compound] = valCompound;
}
} |
fichier test.cpp
Code:
1 2 3 4 5 6 7 8 9 10
|
#include "GSMEnthalpyData.h"
int main()
{
GsmAnalysis1 analyse = GsmAnalysis1();
analyse.setCompoundByName("C", 2.99);
return 0;
} |