Re: Error C2535 With vector ("member function already defined")
Here's an excerpt from C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\xmemory:
62 // TEMPLATE CLASS allocator
63 template<class _Ty>
64 class allocator
65 { // generic allocator for objects of class _Ty
66 public:
67 typedef _SIZT size_type;
68 typedef _PDFT difference_type;
69 typedef _Ty _FARQ *pointer;
70 typedef const _Ty _FARQ *const_pointer;
71 typedef _Ty _FARQ& reference;
72 typedef const _Ty _FARQ& const_reference;
73 typedef _Ty value_type;
74
75 template<class _Other>
76 struct rebind
77 { // convert an allocator<_Ty> to an allocator <_Other>
78 typedef allocator<_Other> other;
79 };
80
81 pointer address(reference _Val) const
82 { // return address of mutable _Val
83 return (&_Val);
84 }
85
86 const_pointer address(const_reference _Val) const
87 { // return address of nonmutable _Val
88 return (&_Val);
89 }
90
91 allocator()
92 { // construct default allocator (do nothing)
93 }
94
95 allocator(const allocator<_Ty>&)
96 { // construct by copying (do nothing)
97 }
Thanks for all your help,
-- Swen
"Tom Widmer [VC++ MVP]" wrote:
Swen Johnson wrote:
I'm unable to compile the most trivial program using a vector with Visual
Studio 2003 (version 7.1.3008).
It worked fine with 6.0.
-------------------------------------
#include "StdAfx.h"
#include <vector>
class MyTest
{
public:
MyTest(void) {};
~MyTest(void) {};
};
static void func () {
std::vector<MyTest> myVec;
MyTest myTest;
myVec.push_back(myTest);
}
-------------------------------------
------ Build started: Project: VectorTest, Configuration: Debug Win32 ------
Compiling...
MyTest.cpp
c:\Program Files\Microsoft Visual Studio .NET 2003\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 MyTest
]
That error is interesting, since in my VC2003, line 87 of <xmemory> does
not include any mention of the address member function. What does your
line 87 (and surrounding lines) say? It is also very strange that you
are managing to trigger creation of std::allocator<const MyTest>, rather
than just std::allocator<MyTest> (which would not cause the error you
are seeing). There has to be something severely messed up with your
header configuration.
Tom