Re: reference to const static object variable
sorry,
The example should have been:
class MyObj
{
public:
MyObj()
{
std::vector<std::string> t;
t.push_back("zzz");
l_["a"] = t;
}
std::map<std::string,
std::vector<std::string> > l_;
};
const static MyObj obj;
int main()
{
const std::vector<std::string> ®exList = obj.l_["key"];
}
-----
I want to maintain the const-ness of MyObj, and have read access to
the std::vector within std::map...
and the error message says:
passing `const
map<basic_string<char,string_char_traits<char>,__default_alloc_template<fal=
se,
0>
,vector<basic_string<char,string_char_traits<char>,__default_alloc_templat=
e<false,
0>
,allocator<basic_string<char,string_char_traits<char>,__default_alloc_temp=
late<false,
0> > >
,less<basic_string<char,string_char_traits<char>,__default_alloc_template<=
false,
0> >
,allocator<vector<basic_string<char,string_char_traits<char>,__default_all=
oc_template<false,
0>
,allocator<basic_string<char,string_char_traits<char>,__default_alloc_temp=
late<false,
0> > > > > >' as `this' argument of `class
vector<basic_string<char,string_char_traits<char>,__default_alloc_template<=
false,
0>
,allocator<basic_string<char,string_char_traits<char>,__default_alloc_temp=
late<false,
0> > > > &
map<basic_string<char,string_char_traits<char>,__default_alloc_template<fal=
se,
0>
,vector<basic_string<char,string_char_traits<char>,__default_alloc_templat=
e<false,
0>
,allocator<basic_string<char,string_char_traits<char>,__default_alloc_temp=
late<false,
0> > >
,less<basic_string<char,string_char_traits<char>,__default_alloc_template<=
false,
0> >
,allocator<vector<basic_string<char,string_char_traits<char>,__default_all=
oc_template<false,
0>
,allocator<basic_string<char,string_char_traits<char>,__default_alloc_temp=
late<false,
0> > > > > >::operator [](const string &)' discards qualifiers
Which I don't understand.
const static MyObj obj;
On Nov 14, 12:30 pm, Obnoxious User <O...@127.0.0.1> wrote:
On Fri, 14 Nov 2008 11:23:28 -0800, Bob Doe wrote:
I have a const static object. What is the right syntax to get a
reference to the std::vector within the std::map variable?:
class MyObj
{
public:
...
std::map<std::string,
std::vector<std::string> > l_;
};
static MyObj obj;
int main()
{
...
const std::vector<std::string> ®exList = obj.l_["key"]; //
compiler error
...
};
Did you care to read the error message? What did it say?
--
OU
Remember 18th of June 2008, Democracy died that afternoon.http://frapedia=
..se/wiki/Information_in_English