Error C2662 and C2664

I get two errors with MS VC++ 6 c/w Sp5 which I do not understand!

The first error c2662 is on a set::clear command
and the second, error c2664, is on the 3rd param of a for_each algorithm.

If anyone can explain these to me I would appreciate it.

Here is the code:

In class definition:

typedef struct tag_CommentKey {
string section; // Section where comment appears
string key; // key in section where comment appears
} COMMENTKEY;

typedef struct tag_Comment {
int sequence; // Order of command line (0 for inline, n for stand-alone
int position; // Position on line
string comments; // Comment text
} COMMENTS;

typedef multimap<COMMENTKEY, COMMENTS> m_IniComment; // list of comments
typedef set<COMMENTS> m_CommentSet ; // Some comments

COMMENTKEY m_CommentKey;
COMMENTS m_CommentText;

m_IniComment m_IniComments; // Keyed Comments list
m_IniComment::iterator m_itIniComment;

m_CommentSet m_Comments;
m_CommentSet::iterator m_itComments;

void setComments ( COMMENTKEY & commentKey, COMMENTS & commentText );
void getComments ( void ) const;
void setCommentSet ( const pair<COMMENTKEY, COMMENTS> & comment );


and in the implementation:

void
IniFile::setComments ( COMMENTKEY & commentKey, COMMENTS & commentText )
{
m_IniComments.insert (m_IniComment::value_type(commentKey, commentText));
return;
}

void
IniFile::getComments ( void ) const
{
int number = m_IniComments.count (m_CommentKey);

if (number > 0) {
if (!m_Comments.empty()) {
m_Comments.clear (); // this gets an error C2662!
}
pair<m_IniComment::iterator, m_IniComment::iterator> ret =
m_IniComments.equal_range (m_CommentKey);

for_each (ret.first, ret.second, setCommentSet); // this gets an error c2664 on param 3
}
return;
}

void
IniFile::setCommentSet ( const pair<COMMENTKEY, COMMENTS> & comment )
{
m_Comments.insert (m_CommentSet::value_type (comment.second));
return;
}

Here are the actual errors:

--------------------Configuration: Test Ini File - Win32 Debug--------------------
Compiling...
IniFile.cpp
e:\programming\projects\STL studies\inifile.cpp(763) : error C2662: 'clear' : cannot convert 'this' pointer from 'const class std::set<struct IniFile::tag_Comment,struct std::less<struct IniFile::tag_Comment>,class std::allocator<struct IniFile::tag_Comment> >' to 'class std::set<struct IniFile::tag_Comment,struct std::less<struct IniFile::tag_Comment>,class std::allocator<struct IniFile::tag_Comment> > &'
Conversion loses qualifiers
e:\\programming\projects\game development\game engine\inifile.cpp(767) : error C2664: 'for_each' : cannot convert parameter 3 from 'void (const struct std::pair<struct IniFile::tag_CommentKey,struct IniFile::tag_Comment> &)' to 'void (__thiscall *)(const struct std::pair<struct IniFile::tag_CommentKey,struct IniFile::tag_Comment> &)'
None of the functions with this name in scope match the target type
IniFileTest.cpp
Error executing cl.exe.

Test Ini File.exe - 2 error(s), 0 warning(s)
Last edited on
OK, I corrected the first error (C2662).

I found the explication on MSDN: I removed the "const" qualifier from the getComments definition:

void getComments ( void );
instead of:
void getComments ( void ) const;

But for the second.... MSDN did not help.

Topic archived. No new replies allowed.