Discussion:
C2440 & C2439 Errors
(too old to reply)
Mike Copeland
2009-10-12 22:33:56 UTC
Permalink
The following code fails to compile (VC6.0; errors C2440 & C2439),
and the offending code is the "find_if" line in main. (As with most MS
error diagnostics,) I can't make any sense out of the messages and don't
know what to do to correct the errors. Please advise. TIA

#pragma warning (disable:4786)
#include <map>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

typedef struct ChipRec
{
int bibNum;
string entName;
} tData;
typedef multimap<string, ChipRec> CHIPINFO;
CHIPINFO mmci;
multimap<string, ChipRec>::iterator cIter;

tData tWork;
tData qWork;
typedef map<int, ChipRec> BCI;
BCI bci;
map<int, ChipRec>::iterator bIter;

class NameMatch
{
string m_name;
public:
NameMatch(string const &name) : m_name(name) {}
bool operator()(const map<int, ChipRec>::value_type const &v)
const
{
string nameWork;
nameWork = v.second.entName;
return nameWork == m_name;
}
};

int main()
{
string tStr = "The Phantom Spitter";
CHIPINFO::iterator it = find_if(mmci.begin(), mmci.end(),
NameMatch(tStr));
return 0;
}
Igor Tandetnik
2009-10-13 00:32:55 UTC
Permalink
Post by Mike Copeland
typedef struct ChipRec
{
int bibNum;
string entName;
} tData;
typedef multimap<string, ChipRec> CHIPINFO;
CHIPINFO mmci;
class NameMatch
{
string m_name;
NameMatch(string const &name) : m_name(name) {}
bool operator()(const map<int, ChipRec>::value_type const &v)
const
};
int main()
{
string tStr = "The Phantom Spitter";
CHIPINFO::iterator it = find_if(mmci.begin(), mmci.end(),
NameMatch(tStr));
NameMatch::operator() takes map<int, ChipRec>::value_type. mmci is multimap<string, ChipRec>. It's not clear why you expect this to work.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Ben Voigt [C++ MVP]
2009-10-14 00:02:51 UTC
Permalink
Furthermore, just because you can't understand the errors doesn't mean we
haven't seen them before. You did a great job posting the right amount of
code, in the future post the error messages as well.
Post by Mike Copeland
The following code fails to compile (VC6.0; errors C2440 & C2439),
and the offending code is the "find_if" line in main. (As with most MS
error diagnostics,) I can't make any sense out of the messages and don't
know what to do to correct the errors. Please advise. TIA
#pragma warning (disable:4786)
#include <map>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef struct ChipRec
{
int bibNum;
string entName;
} tData;
typedef multimap<string, ChipRec> CHIPINFO;
CHIPINFO mmci;
multimap<string, ChipRec>::iterator cIter;
tData tWork;
tData qWork;
typedef map<int, ChipRec> BCI;
BCI bci;
map<int, ChipRec>::iterator bIter;
class NameMatch
{
string m_name;
NameMatch(string const &name) : m_name(name) {}
bool operator()(const map<int, ChipRec>::value_type const &v)
const
{
string nameWork;
nameWork = v.second.entName;
return nameWork == m_name;
}
};
int main()
{
string tStr = "The Phantom Spitter";
CHIPINFO::iterator it = find_if(mmci.begin(), mmci.end(),
NameMatch(tStr));
return 0;
}
Loading...