C
Charlie
Dear all,
I am stuck on this problem, couldn't find an answer on any C++ book in
the bookshop.
Following is a cut of my program, and its error message:
============================================
280 map<char[9],vector<int> > _dict;
281 char* op_addr = op.get_address();
282 int op_time = op.get_time_stamp();
283 _dict[op_addr].push_back(op_time);
==========================================
class.cc:283: no match for `std::map<char[9], std::vector<int,
std::allocator<int> >, std::less<char[9]>,
std::allocator<std:
air<const
char[9], std::vector<int, std::allocator<int> > > > >& [char*&]'
operator
/usr/include/c++/3.2.2/bits/stl_map.h:221: candidates are: _Tp&
std::map<_Key,
_Tp, _Compare, _Alloc>:
perator[](const _Key&) [with _Key =
char[9], _Tp =
std::vector<int, std::allocator<int> >, _Compare =
std::less<char[9]>,
_Alloc = std::allocator<std:
air<const char[9], std::vector<int,
std::allocator<int> > > >]
=============================================
I wrote a small test program, to represent this problem, using char[]
as key type for a map. But it always fails to compile. I really don't
know how to make this char array to work. The reason I have to use
char[] in stread of stl::string, because it's primitive type, save lots
of memory, and also can help the process to give memory back to OS.
(input file is about 6Gb)
#include <iostream>
#include <map>
int main()
{
typedef std::map<char[9],int > DictType;
DictType _dict;
char _addr[9] = "12345678";
_dict.insert( DictType::value_type(_addr, 3) );
std::cout<<_dict[_addr]<<std::endl;
return 0;
}
It fails to compile, with following error message:
[root@localhost Trace_ana_stack_12May]# g++ -o try_char_map.exe
try_char_map.cc
/usr/include/c++/3.2.2/bits/stl_pair.h: In constructor `std:
air<_T1,
_T2>:
air(const _T1&, const _T2&) [with _T1 = const char[9], _T2 =
int]':
try_char_map.cc:10: instantiated from here
/usr/include/c++/3.2.2/bits/stl_pair.h:84: ISO C++ forbids assignment
of arrays
=========================================
I am really got no idea. Any help or comment is highly appreciate!
Many thanks!
Charlie
I am stuck on this problem, couldn't find an answer on any C++ book in
the bookshop.
Following is a cut of my program, and its error message:
============================================
280 map<char[9],vector<int> > _dict;
281 char* op_addr = op.get_address();
282 int op_time = op.get_time_stamp();
283 _dict[op_addr].push_back(op_time);
==========================================
class.cc:283: no match for `std::map<char[9], std::vector<int,
std::allocator<int> >, std::less<char[9]>,
std::allocator<std:
char[9], std::vector<int, std::allocator<int> > > > >& [char*&]'
operator
/usr/include/c++/3.2.2/bits/stl_map.h:221: candidates are: _Tp&
std::map<_Key,
_Tp, _Compare, _Alloc>:
char[9], _Tp =
std::vector<int, std::allocator<int> >, _Compare =
std::less<char[9]>,
_Alloc = std::allocator<std:
std::allocator<int> > > >]
=============================================
I wrote a small test program, to represent this problem, using char[]
as key type for a map. But it always fails to compile. I really don't
know how to make this char array to work. The reason I have to use
char[] in stread of stl::string, because it's primitive type, save lots
of memory, and also can help the process to give memory back to OS.
(input file is about 6Gb)
#include <iostream>
#include <map>
int main()
{
typedef std::map<char[9],int > DictType;
DictType _dict;
char _addr[9] = "12345678";
_dict.insert( DictType::value_type(_addr, 3) );
std::cout<<_dict[_addr]<<std::endl;
return 0;
}
It fails to compile, with following error message:
[root@localhost Trace_ana_stack_12May]# g++ -o try_char_map.exe
try_char_map.cc
/usr/include/c++/3.2.2/bits/stl_pair.h: In constructor `std:
_T2>:
int]':
try_char_map.cc:10: instantiated from here
/usr/include/c++/3.2.2/bits/stl_pair.h:84: ISO C++ forbids assignment
of arrays
=========================================
I am really got no idea. Any help or comment is highly appreciate!
Many thanks!
Charlie