make a map out of two maps

M

Manzanita

Hi.

VC++ 7.0 issues this error when i try to make a container out of two
std::map, i want this container to provide me with o(log(n)) searches in
both types: key_type and mapped_type, and some further features. The code
and the error are like follows. Any workaround will be very helpful.

Thank you very much in advance.
David.

-------- mapa.h ---------

#include<map>

namespace David{

using namespace std;


template<class T1, class T2, class Cmp1 = less<T1>,
class Cmp2 = less<T2>, class A1 = allocator<pair<const T1, T2> >,
class A2 = allocator<pair<const T2, T1> > > class mapa{

private:
map<const T1, T2, Cmp1, A1> map1;
map<const T2, T1, Cmp2, A2> map2;
typedef const T1 key_type;
typedef T2 mapped_type;
};
----------- end of mapa.h ---
----------- main.cpp --------
int main(){
David::mapa<int, char> gMap;
}

-----------------------------

C:\Archivos de programa\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 declared or defined
with
[
_Ty=const std::_Tree<std::_Tmap_traits<const
char,int,std::less<char>,std::allocator<std::pair<const
char,int>>,false>>::key_type
]
 
R

Rob Williscroft

Manzanita wrote in
[snip]
-------- mapa.h ---------

#include<map>

namespace David{

using namespace std;


template<class T1, class T2, class Cmp1 = less<T1>,
class Cmp2 = less<T2>, class A1 = allocator<pair<const T1, T2> >,
class A2 = allocator<pair<const T2, T1> > > class mapa{

private:
map<const T1, T2, Cmp1, A1> map1;
map<const T2, T1, Cmp2, A2> map2;
typedef const T1 key_type;
typedef T2 mapped_type;
};

} /* David:: */
----------- end of mapa.h ---
----------- main.cpp --------
int main(){
David::mapa<int, char> gMap;
}

With an added closing '}' your code compiled on 2 out of three compilers
I tried, on the third I removed the (unnessasery) const from

map<const T1, T2, Cmp1, A1> map1;
map<const T2, T1, Cmp2, A2> map2;

I.e. changed it to:

map<T1, T2, Cmp1, A1> map1;
map<T2, T1, Cmp2, A2> map2;

And it compiled ok. I don't currently have VC 7.0 installed, but FWIW
you code compiled unmodified on VC7.1.

[snip]

Rob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top