By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,209 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,209 IT Pros & Developers. It's quick & easy.

STL code compiling problems in VS 2005

P: n/a
I have a piece of STL code which compiled perfectly with VC++ 6.0 and
VS .NET 2003 but I get loads of errors for it in VS 2005.

The code is as follows:

class CTimeKey: public pair<wstring, wstring{};
class CTimeFactors
{
public:
double calendar_factor;
double calendar_days;
bool pattern_check;
double pattern_factor;
};

class CTimeLine: public map<CTimeKey, CTimeFactors{};

CTimeLine::iterator l_time_iterator;
....
if (l_time_iterator == NULL) {
....
}

The error is for the NULL comparison operation and is as follows:

error C2678: binary '==' : no operator found which takes a left-hand
operand of type 'std::_Tree<_Traits>::iterator' (or there is no
acceptable conversion)
with
[

_Traits=std::_Tmap_traits<CTimeKey,CTimeFactors,st d::less<CTimeKey>,std::allocator<std::pair<const
CTimeKey,CTimeFactors>>,false>
]
C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK
\include\guiddef.h(192): could be 'int operator ==(const GUID &,const
GUID &)'
C:\Program Files\Microsoft Visual Studio 8\VC\include
\xtree(287): or 'bool std::_Tree<_Traits>::const_iterator::operator
==(const std::_Tree<_Traits>::const_iterator &) const'
with
[

_Traits=std::_Tmap_traits<CTimeKey,CTimeFactors,st d::less<CTimeKey>,std::allocator<std::pair<const
CTimeKey,CTimeFactors>>,false>
]
while trying to match the argument list
'(std::_Tree<_Traits>::iterator, int)'
with
[

_Traits=std::_Tmap_traits<CTimeKey,CTimeFactors,st d::less<CTimeKey>,std::allocator<std::pair<const
CTimeKey,CTimeFactors>>,false>
]
Any ideas how to resolve this?

Thanks and regards,
Ankan

Feb 22 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
an************@gmail.com wrote:
I have a piece of STL code which compiled perfectly with VC++ 6.0 and
VS .NET 2003 but I get loads of errors for it in VS 2005.
Well, first you should probably post in a C++ newsgroup instead of a C#
newsgroup.
>
The code is as follows:

class CTimeKey: public pair<wstring, wstring{};
class CTimeFactors
{
public:
double calendar_factor;
double calendar_days;
bool pattern_check;
double pattern_factor;
};

class CTimeLine: public map<CTimeKey, CTimeFactors{};

CTimeLine::iterator l_time_iterator;
...
if (l_time_iterator == NULL) {

[snipped more code]

Any ideas how to resolve this?
Iterators are not required to be comparable to null. It might work on some
implementations, but there's no guarantee. Instead, you need to compare the
iterator to another iterator, such as the one returned by end():

if (l_time_iterator == end())

It's also not a good idea to derive from std::pair or std::map since those
classes weren't designed to work as a base class. As long as you don't ever
call delete through a pointer to the base class, you won't have any
problems, but it's usually recommended to avoid the construct in the first
place.

-cd
Feb 22 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.