Help !! compile error with VS2005, but ok with VC6

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Dear all,

recently I transform my project from vc6 to vs2005, it occur to the
following error:

d:\Program Files\Microsoft Visual Studio 8\VC\ce\include\xtree(1172) : error
C3848: expression having type 'const CFormatter::ltwsz' would lose some
const-volatile qualifiers in order to call 'bool CFormatter::ltwsz::operator
()(const wchar_t *,const wchar_t *)'
d:\Program Files\Microsoft Visual Studio 8\VC\ce\include\xtree(1167)
: while compiling class template member function
'std::_Tree_nod<_Traits>::_Node *std::_Tree<_Traits>::_Lbound(const wchar_t
*const &) const'
with
[
_Traits=std::_Tmap_traits<const wchar_t
*,std::wstring,CFormatter::ltwsz,std::allocator<std::pair<const wchar_t
*const ,std::wstring>>,false>
]
d:\Program Files\Microsoft Visual Studio 8\VC\ce\include\map(82) :
see reference to class template instantiation 'std::_Tree<_Traits>' being
compiled
with
[
_Traits=std::_Tmap_traits<const wchar_t
*,std::wstring,CFormatter::ltwsz,std::allocator<std::pair<const wchar_t
*const ,std::wstring>>,false>
]

d:\ccm_wa\jethzh\nav_sdk#arbrbg#1-jethzh#uida35611\tovs2005\nav_sdk\source\hmi\Formatter.h(201)
: see reference to class template instantiation 'std::map<_Kty,_Ty,_Pr>'
being compiled
with
[
_Kty=const wchar_t *,
_Ty=std::wstring,
_Pr=CFormatter::ltwsz
]

my source code as follows:

/**
* @file
* Formatter.h
* @brief
* FIXME
* @par Author:
* - Collin Brown
* - Phone +420 241 010 640
* - ANF DATA
* - Jan Hudec
* - Phone +420 241 010 651
* - ANF DATA
* - Marian Jaworski
* - Phone +420 241 010 649
* - ANF DATA
* - Marek Krejza
* - Phone +420 241 010 641
* - ANF DATA
* @par PL:
* - Lutz Tiede
* - Phone +49(941)790-5165
* - SiemensVDO
* @par Responsible Architect:
* - Josef Baumgartner
* - Phone +49(941)790-6779
* - SiemensVDO
* @par Project:
* Fortuna Navigation
* @par SW-Component:
* Navigation Hmi
* @par SW-Package:
* HMI
* @par SW-Module:
* Formatter
* @par Description:
* FIXME
* @note
*
* @par Copyright Notice:
* Copyright (C) Siemens AG 2006
* Siemens VDO AG
* Alle Rechte vorbehalten. All Rights Reserved.
*
* The reproduction, transmission or use of this document or its contents is
* not permitted without express written authority.
* Offenders will be liable for damages. All rights, including rights created
* by patent grant or registration of a utility model or design, are reserved.
*/

#ifndef __FORMATTER_H__
#define __FORMATTER_H__

/*
* FIXME FIXME FIXME
* GET RID OF THIS BLOODY HACK!
*
* In multi-threaded application the pair class needs a constructor and
* destructor for a std::_Lockit object and does not have it. But if we
* undefine _MT around inclusion of map, that class is defined to do nothing
* and we are OK.
*
* TODO: Find a way to properly link in or implement this std::_Lockit class
* or rewrite this code to not use std::map.
* FIXME FIXME FIXME
*/
#ifdef _MT
# undef _MT
# include <map>
# define _MT 1
#else
# include <map>
#endif

#include <string>
#include <string.h>

#include "ResourceManager.h"
#include "Utils.h"

/** @brief Class for formating strings.
*
* This class can be used for interpolating values into string, when the
* order of the values should be given by the format string (ie. different
* translations may need to order objects differently).
*/
class CFormatter : public CUtils
{
public:
/*
* NOTEME: We might need to have an options to apply different format
* strings for:
* - Negative (there are no objects)
* - Singular (there is one object)
* - Dual (there are two or two to four or two to something objects,
* depending on language)
* - Plural (there are many objects, except for some languages choice is
* governed by the last digit and not the whole number. And as a bonus,
* 10-19 is sometimes exception from exception)
*/

/** @brief Default construrctor, leaving the format unset. */
CFormatter() {}

/** @brief Constructor, setting format from string ID. */
template<typename FormatType>
CFormatter(FormatType format)
{
SetFormat(format);
}

/** @brief Sets the format string.
*
* The format string can be a std::wstring, CString, wchar_t array, or
* resource string ID.
*/
inline CFormatter& SetFormat(const wchar_t* format)
{
m_fmt = format;
return *this;
}

inline CFormatter& SetFormat(std::wstring format)
{
m_fmt = format;
return *this;
}

inline CFormatter& SetFormat(UINT format)
{
m_fmt = (LPCTSTR)(CResourceManager::GetInstance()->GetString(format));
return *this;
}

/** @brief Read the result as a std::wstring.
*
* Returning std::wstring has the advantage over CString, that it shares
* the contents.
*/
operator const std::wstring();

/** @brief Read the result as a C string.
*
* Return const wchar_t*. This simply points to the internal std::wstring
* buffer.
*/
operator const wchar_t*();

/** @brief Read the result to a CString.
*
* This fills in a CString with the result value.
*/
void Get(CString& strResult);

/** @brief Add a value.
*
* Add a value for given key formatting it using standard wsprintf
* formating.
* @param key The name of the item. The replaced string looks like
* environment variable expansion, that is
* <tt>%</tt><i>key</i><tt>%</tt>.
* @param format wsprintf-style format for the value.
* @param value The value, of any type formatable by wsprintf.
* @return Returns itself, so calls to this method can be chained.
*/
template<typename ValueType>
CFormatter& Add(LPCTSTR key, LPCTSTR format, ValueType value)
{
CString buf;
buf.Format(format, value);
m_map[key] = buf;
return *this;
}

/** @brief Add a string value.
*
* Add a string value for given key. This has the advantage over
* Add(LPCTSTR, LPCTSTR, ValueType) that it does not need to format the
* value.
* @param key The name of the item.
* @param value The value as wchar_t array, CString or resource ID.
*/
template<typename ValueType>
CFormatter& Add(LPCTSTR key, ValueType value)
{
m_map[key] = ToWString(value);
return *this;
}

private:
void Format();

struct ltwsz
{
bool operator()(const wchar_t* left, const wchar_t* right)
{
return wcscmp(left, right) < 0;
}
};

std::wstring m_fmt;
std::map<const wchar_t *, std::wstring, ltwsz> m_map;
std::wstring m_res;
};

#endif //__FORMATTER_H__


.



Relevant Pages

  • Re: unit testing C++ code from perl
    ... void ReportAssert(char const* description, char const* filename, int const ... That's probably the complaint string for an error. ... Then we have a filename and lineNumber. ... void FormatToStream(MemoryOutStream& stream, char const* format, ValueType const& value) ...
    (comp.programming)
  • Re: format a specific letter by code
    ... You left a lot of detail out, so I constructed a general "copy data, format the v" macro for you to use, just change the values in the four Const statements to match your actual setup... ... Dim TextToCopy As String ... .Bold = True ...
    (microsoft.public.excel.programming)
  • Re: Formula to format selective part in a text
    ... what is the Cell Format for that date? ... its characters and, unfortunately, formulas do not produce text string ... Const RangeToMonitor As String = "A1" ...
    (microsoft.public.excel.programming)
  • Re: Formula Text String: Formatting Text and Numbers?
    ... If I havea text string formula and I insert a number. ... If the number of candy bars is in C2, ... will format the value as you describe. ... Const s2 As String = " candy bars from the grocery store." ...
    (microsoft.public.excel.misc)
  • printing bits ... the right way
    ... \param str The array of characters where the resulting string is to ... \param format A custom format string specific to converting ... render an integer type into a binary string. ...
    (comp.lang.c)