Problem in porting code from VC++ 6.0 to VS.Net (using STL) 
Author Message
 Problem in porting code from VC++ 6.0 to VS.Net (using STL)

Hi,

Anyone can help me the following problem.
When I try to port one probject created in VC++ 6.0 to VS.Net, I got the
following compile error. By the way, I used STL in the porting project.
---------------------------------------  Compile
error ----------------------------------
...
c:\Program Files\Microsoft Visual Studio.NET\Vc7\include\xmemory(87) : error
C2535: 'std::allocator<_Ty>::pointer
std::allocator<_Ty>::address(std::allocator<_Ty>::reference) const' : member
function already defined or declared
with
[
_Ty=const std::_Tree<std::_Tmap_traits<const
std::string,splitOptions,std::less<const
std::string>,std::allocator<std::pair<const
std::string,splitOptions>>,false>>::key_type
]
c:\Program Files\Microsoft Visual Studio.NET\Vc7\include\xmemory(81) : see
declaration of 'std::allocator<_Ty>::address'
with
[
_Ty=const std::_Tree<std::_Tmap_traits<const
std::string,splitOptions,std::less<const
std::string>,std::allocator<std::pair<const
std::string,splitOptions>>,false>>::key_type
]
c:\Program Files\Microsoft Visual Studio.NET\Vc7\include\xtree(122) : see
reference to class template instantiation 'std::allocator<_Ty>' being
compiled
with
[
_Ty=const std::_Tree<std::_Tmap_traits<const
std::string,splitOptions,std::less<const
std::string>,std::allocator<std::pair<const
std::string,splitOptions>>,false>>::key_type
]
c:\Program Files\Microsoft Visual Studio.NET\Vc7\include\map(77) : see
reference to class template instantiation 'std::_Tree<_Traits>' being
compiled
with
[
_Traits=std::_Tmap_traits<const std::string,splitOptions,std::less<const
std::string>,std::allocator<std::pair<const
std::string,splitOptions>>,false>
]
c:\MyProject\DotNet_Projects\MgdPreClass\CDataSetDLL\ConfigConstraints.h(141
) : see reference to class template instantiation
'std::map<_Kty,_Ty,_Pr,_Alloc>' being compiled
with
[
_Kty=const std::string,
_Ty=splitOptions,
_Pr=std::less<const std::string>,
_Alloc=std::allocator<std::pair<const std::string,splitOptions>>
]
---------------------------------------------------------------------
mike zhao



Tue, 22 Jun 2004 06:03:23 GMT  
 Problem in porting code from VC++ 6.0 to VS.Net (using STL)
Hi,

I got a very strange problem. Anybody can help me on this?
The following code works just fine in VC++ 6.0, but it cannot be compiled
under VS.Net.

----------------------------------------------------------------------------
// TestSTL.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#pragma warning ( disable : 4786)
#pragma warning ( push, 3 )
#pragma warning ( disable : 4100)
#pragma warning ( disable : 4663)
#pragma warning ( disable : 4018)
#pragma warning ( disable : 4146)

#include <bitset>
#include <map>
#include <vector>

#define FLAGS_SIZE  96

typedef std::bitset<FLAGS_SIZE> splitOptions;

typedef std::pair<const std::string,splitOptions> nameFlagPair;
typedef std::map<const std::string,splitOptions> FUNC_FLAG_MAP;

__declspec(dllexport) FUNC_FLAG_MAP mapedFlags;

int main(int argc, char* argv[])
{
 printf("Hello World!\n");
 std::vector<int> a;
 a.push_back(1);
 a.push_back(2);

 return 0;

Quote:
}

----------------------- Compile error -------------------
TestSTL.cpp
c:\Program Files\Microsoft Visual Studio.NET\Vc7\include\xmemory(87) : error
C2535: 'std::allocator<_Ty>::pointer
std::allocator<_Ty>::address(std::allocator<_Ty>::reference) const' : member
function already defined or declared
        with
        [
            _Ty=const std::_Tree<std::_Tmap_traits<const
std::string,splitOptions,std::less<const
std::string>,std::allocator<std::pair<const
std::string,splitOptions>>,false>>::key_type
        ]
        c:\Program Files\Microsoft Visual Studio.NET\Vc7\include\xmemory(81)
: see declaration of 'std::allocator<_Ty>::address'
        with
        [
            _Ty=const std::_Tree<std::_Tmap_traits<const
std::string,splitOptions,std::less<const
std::string>,std::allocator<std::pair<const
std::string,splitOptions>>,false>>::key_type
        ]
        c:\Program Files\Microsoft Visual Studio.NET\Vc7\include\xtree(122)
: see reference to class template instantiation 'std::allocator<_Ty>' being
compiled
        with
        [
            _Ty=const std::_Tree<std::_Tmap_traits<const
std::string,splitOptions,std::less<const
std::string>,std::allocator<std::pair<const
std::string,splitOptions>>,false>>::key_type
        ]
        c:\Program Files\Microsoft Visual Studio.NET\Vc7\include\map(77) :
see reference to class template instantiation 'std::_Tree<_Traits>' being
compiled
        with
        [
            _Traits=std::_Tmap_traits<const
std::string,splitOptions,std::less<const
std::string>,std::allocator<std::pair<const
std::string,splitOptions>>,false>
        ]
        c:\MyTestCode\TestSTL\TestSTL.cpp(24) : see reference to class
template instantiation 'std::map<_Kty,_Ty,_Pr,_Alloc>' being compiled
        with
        [
            _Kty=const std::string,
            _Ty=splitOptions,
            _Pr=std::less<const std::string>,
            _Alloc=std::allocator<std::pair<const std::string,splitOptions>>
        ]

Build log was saved at "file://c:\MyTestCode\TestSTL\Debug\BuildLog.htm"
TestSTL - 1 error(s), 0 warning(s)



Wed, 23 Jun 2004 04:45:43 GMT  
 Problem in porting code from VC++ 6.0 to VS.Net (using STL)
I suspect it is the const template arguments that are causing you a problem.
Imagine I have the following class template

template<typename T>
class X {
public:
   void f(const T &) {
   }
   void f(T &) {
   }

Quote:
};

and I specialize it with "const int" - this will lead to multiple definition
errors as it will look to the compiler that I am trying to define

void f(const int &)

twice

--
Jonathan Caves
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2002 Microsoft Corporation. All rights
reserved.

http://www.microsoft.com/info/cpyright.htm.

Quote:
> Hi,

> I got a very strange problem. Anybody can help me on this?
> The following code works just fine in VC++ 6.0, but it cannot be compiled
> under VS.Net.

> --------------------------------------------------------------------------
--
> // TestSTL.cpp : Defines the entry point for the console application.
> //

> #include "stdafx.h"

> #pragma warning ( disable : 4786)
> #pragma warning ( push, 3 )
> #pragma warning ( disable : 4100)
> #pragma warning ( disable : 4663)
> #pragma warning ( disable : 4018)
> #pragma warning ( disable : 4146)

> #include <bitset>
> #include <map>
> #include <vector>

> #define FLAGS_SIZE  96

> typedef std::bitset<FLAGS_SIZE> splitOptions;

> typedef std::pair<const std::string,splitOptions> nameFlagPair;
> typedef std::map<const std::string,splitOptions> FUNC_FLAG_MAP;

> __declspec(dllexport) FUNC_FLAG_MAP mapedFlags;

> int main(int argc, char* argv[])
> {
>  printf("Hello World!\n");
>  std::vector<int> a;
>  a.push_back(1);
>  a.push_back(2);

>  return 0;
> }

> ----------------------- Compile error -------------------
> TestSTL.cpp
> c:\Program Files\Microsoft Visual Studio.NET\Vc7\include\xmemory(87) :
error
> C2535: 'std::allocator<_Ty>::pointer
> std::allocator<_Ty>::address(std::allocator<_Ty>::reference) const' :
member
> function already defined or declared
>         with
>         [
>             _Ty=const std::_Tree<std::_Tmap_traits<const
> std::string,splitOptions,std::less<const
> std::string>,std::allocator<std::pair<const
> std::string,splitOptions>>,false>>::key_type
>         ]
>         c:\Program Files\Microsoft Visual

Studio.NET\Vc7\include\xmemory(81)
Quote:
> : see declaration of 'std::allocator<_Ty>::address'
>         with
>         [
>             _Ty=const std::_Tree<std::_Tmap_traits<const
> std::string,splitOptions,std::less<const
> std::string>,std::allocator<std::pair<const
> std::string,splitOptions>>,false>>::key_type
>         ]
>         c:\Program Files\Microsoft Visual

Studio.NET\Vc7\include\xtree(122)

- Show quoted text -

Quote:
> : see reference to class template instantiation 'std::allocator<_Ty>'
being
> compiled
>         with
>         [
>             _Ty=const std::_Tree<std::_Tmap_traits<const
> std::string,splitOptions,std::less<const
> std::string>,std::allocator<std::pair<const
> std::string,splitOptions>>,false>>::key_type
>         ]
>         c:\Program Files\Microsoft Visual Studio.NET\Vc7\include\map(77) :
> see reference to class template instantiation 'std::_Tree<_Traits>' being
> compiled
>         with
>         [
>             _Traits=std::_Tmap_traits<const
> std::string,splitOptions,std::less<const
> std::string>,std::allocator<std::pair<const
> std::string,splitOptions>>,false>
>         ]
>         c:\MyTestCode\TestSTL\TestSTL.cpp(24) : see reference to class
> template instantiation 'std::map<_Kty,_Ty,_Pr,_Alloc>' being compiled
>         with
>         [
>             _Kty=const std::string,
>             _Ty=splitOptions,
>             _Pr=std::less<const std::string>,
>             _Alloc=std::allocator<std::pair<const

std::string,splitOptions>>

- Show quoted text -

Quote:
>         ]

> Build log was saved at "file://c:\MyTestCode\TestSTL\Debug\BuildLog.htm"
> TestSTL - 1 error(s), 0 warning(s)



Wed, 23 Jun 2004 04:56:34 GMT  
 Problem in porting code from VC++ 6.0 to VS.Net (using STL)


Quote:
> Hi,

> I got a very strange problem. Anybody can help me on this?
> The following code works just fine in VC++ 6.0, but it cannot be compiled
> under VS.Net.

> --------------------------------------------------------------------------

--
...
Quote:
> typedef std::map<const std::string,splitOptions> FUNC_FLAG_MAP;

...

This gives compile errors with VC++ .NET because the C++ Standard Library
there is more conformant.  According to the C++ standard (23.1.2, table 69),
the key type of an associative container like std::map must be Assignable.
That's not true here, since the key is const std::string.

You need to get rid of the const.

...Phil



Wed, 23 Jun 2004 07:22:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problem porting ATL project from VC++ 6.0 to VC++.NET 2003

2. Code which used to compile in VC++ 6.0 gives C2593 error in VC++ .Net

3. VS.NET vs VC++ 6.0

4. Problem using STL in VC 6.0

5. Problem using STL in VC 6.0

6. VC++ 6.0 vs VC++.NET and IBM UDB Stored Procedures

7. Streams: VC++ 6.0 vs VC.NET 2003

8. VC++ 6.0 vs VC++.Net

9. Using VS.NET with 6.0 Compiler

10. Problem converting VC++ 6.0 project to VC++.net

11. Error Compiling VC 6.0 program in VS.net B2

12. Singleton Object Activation .NET 2003 Vs. VC++ 6.0

 

 
Powered by phpBB® Forum Software