Code works in VS2010 but not in VC++ 6.0

Hello,

I'm working on a project, in which I'm using stemming library which works quite perfectly on Visual Studio 2010 (Express) but when I tried to compile the same project in VC++ 6.0, it generated errors. I fixed a few of them but I'm stuck at some. Something related to templates...

I need to do it in VC 6.0 for some reason.

Here is the code (posting only relevant part because of the limitation 9000 characters of forums):

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
68
69
70
71
72
73
/***************************************************************************
                          utilities.h  -  description
                             -------------------
    begin                : Sat Apr 26 2003
    copyright            : (C) 2003 by Blake Madden
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the BSD License.                                *
 *                                                                         *
 ***************************************************************************/

#ifndef __UTILITIES_H__
#define __UTILITIES_H__

#include <algorithm>
#include <functional>
#include <math.h>
#include <cassert>
#include <iterator>

#ifndef M_PI
    #define M_PI 3.1415926535897932384626433832795
#endif

//returns the byte size of an array
#define size_of_array(x) (sizeof(x)/sizeof(x[0]))

[[[[SKIPPED CODE FROM HERE]]]]

[[[[Starting from line # 156 Below]]]]

template<typename _InIt, typename _Pr, typename member_extract_functorT>
inline typename std::iterator_traits<_InIt>::difference_type
    count_member_if(_InIt _First, _InIt _Last,
                    _Pr _Pred, member_extract_functorT get_value)
    {
    //count elements satisfying _Pred
    typename std::iterator_traits<_InIt>::difference_type _Count = 0;

    for (; _First != _Last; ++_First)
        if (_Pred(get_value(*_First)) )
            ++_Count;
    return (_Count);
    }

//determines if number is even
template <typename T>
class even : public std::unary_function<T, bool>
    {
public:
    inline bool operator()(const T& val) const
        { return val%2==0; }
    };

//determines if a value is within a given range
template<typename T>
class within : public std::unary_function<T, bool>
    {
public:
    within(T range_begin, T range_end)
        : m_range_begin(range_begin), m_range_end(range_end)
        {}
    inline bool operator()(T value) const
        { return (value >= m_range_begin && value <= m_range_end); }
private:
    T m_range_begin;
    T m_range_end;
    };

#endif //__UTILITIES_H__ 


Here's the full code of this file:
http://pastebin.com/xM2dRF9P


Here's the error list:

Compiling...
main.cpp
c:\[path]\utilities.h(158) : error C2039: 'difference_type' : is not a member of 'iterator_traits<_It>'
c:\[path]\utilities.h(158) : error C2146: syntax error : missing ';' before identifier 'count_member_if'
c:\[path]\utilities.h(158) : error C2433: 'difference_type' : 'inline' not permitted on data declarations
c:\[path]\utilities.h(158) : error C2501: 'difference_type' : missing storage-class or type specifiers
c:\[path]\utilities.h(158) : error C2059: syntax error : ';'
c:\[path]\utilities.h(158) : error C2065: '_InIt' : undeclared identifier
c:\[path]\utilities.h(158) : error C2146: syntax error : missing ')' before identifier '_First'
c:\[path]\utilities.h(158) : error C2501: 'count_member_if' : missing storage-class or type specifiers
c:\[path]\utilities.h(159) : error C2059: syntax error : ')'
c:\[path]\utilities.h(180) : error C2954: template definitions cannot nest
c:\[path]\utilities.h(185) : error C2065: 'm_range_begin' : undeclared identifier
        c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(185) : error C2065: 'range_begin' : undeclared identifier
        c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(185) : error C2461: 'within<T>' : constructor syntax missing formal parameters
        c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(185) : error C2061: syntax error : identifier 'range_end'
        c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(186) : error C2143: syntax error : missing ';' before '{'
        c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(186) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
        c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(188) : error C2059: syntax error : 'return'
        c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(188) : error C2238: unexpected token(s) preceding ';'
        c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(189) : error C2143: syntax error : missing ';' before 'private'
        c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\program files\microsoft visual studio\vc98\include\wctype.h(194) : error C2061: syntax error : identifier 'wctrans_t'
c:\program files\microsoft visual studio\vc98\include\wctype.h(195) : error C2143: syntax error : missing ';' before '__cdecl'
c:\[path]\meta.h(25) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Command line warning D4028 : minimal rebuild failure, reverting to normal build
Error executing cl.exe.

main.obj - 22 error(s), 1 warning(s)



I'd be thankful for any help/clues.
Last edited on
The C++ standard library which was shipped with VC6, back in the dark ages, is pre-standardization version of the library.

The code you've posted is coded to work with the new version of the library, as you can see by coparing the old and new versions of iterator_traits:

iterator_traits (Visual Sudio 6.0)
http://msdn.microsoft.com/en-gb/library/aa262866%28v=vs.60%29.aspx

1
2
3
4
5
6
template<class It>
    struct iterator_traits {
    typedef It::iterator_category iterator_category;
    typedef It::value_type value_type;
    typedef It::distance_type distance_type;
    };


iterator_traits Struct (Visual Studio 2010)
http://msdn.microsoft.com/en-us/library/vstudio/zdxb97eh%28v=vs.100%29.aspx

1
2
3
4
5
6
7
8
9
10
11
template<class Iterator>
    struct iterator_traits {
        typedef typename Iterator::iterator_category iterator_category;
        typedef typename Iterator::value_type value_type;
        typedef typename Iterator::difference_type difference_type;
        typedef difference_type distance_type;
        typedef typename Iterator::pointer pointer;
        typedef typename Iterator::reference reference;
    };
 
    // plus two other variants 


Basically, you need to repair the code which is trying to use those identifiers which only exist in the newer version of the standard library classes.

Or you could switch to using STLPort rather than the library which came with VC6...

Back in the days when I last worked with VC6, we used STLPort instead, as it's more standard conformant. Not sure if it's pot ot, but the iterator_traits from STLport 5.2.1 (which can be used with VC6) does have a difference_type member!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
template <class _Iterator>
struct iterator_traits {
  typedef typename _Iterator::iterator_category _OriginalTag;
  typedef typename _CategoryMapping<_OriginalTag>::_Tag iterator_category;
#else
template <class _Iterator>
struct iterator_traits {
  typedef typename _Iterator::iterator_category iterator_category;
#endif
  typedef typename _Iterator::value_type        value_type;
  typedef typename _Iterator::difference_type   difference_type;
  typedef typename _Iterator::pointer           pointer;
  typedef typename _Iterator::reference         reference;
};


Worth considering, especially if you are unlucky enough to have to use Visual Studio 6.0 for more than short while or have a lot of code that needs to be repaired to work with VC6 otherwise.

Andy

STLport
http://stlport.sourceforge.net/
http://sourceforge.net/projects/stlport/

How to Use STLPort with Visual C++
http://www.johnpanzer.com/UsingSTLPort.html
Last edited on
Topic archived. No new replies allowed.