私はこれをやろうとしています:2つのベクトルのベクトルを1つのベクトルが値を格納し、2つ目のベクトルが同じ値の参照を格納するようにします。私はboost::reference_wrapper
を使用してトリックを行うと思ったが、それはそう思わない。私はboost::shared_ptr
を使用することができboost :: reference_wrapperを使用してSTLコンテナに参照を格納できますか?
error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from std::basic_string<_Elem,_Traits,_Ax>' to 'const boost::reference
が、私は、参照はより良い私の意図を表現すると思った:私のプラットフォームは、Visual C++ 2008
std::vector<std::string> str_vec;
str_vec.push_back("abc");
str_vec.push_back("cde");
str_vec.push_back("fgh");
std::vector<boost::reference_wrapper<std::string> > str_view;
for(std::vector<std::string>::iterator it = str_vec.begin(); it != str_vec.end(); ++it)
{
str_view.push_back(*it);
}
ですこれはエラーです。このコードはおそらくstd::reference_wrapper
を使用してC++ 11で動作する可能性がありますが、それは私には現在利用できません。
visual C++ 2009とは何ですか?私が知る限り、2008年、2010年、2011年のベータ版があります。 – EdChum