如何在boost :: any map中存储值

时间:2013-03-19 01:00:39

标签: c++

我正在尝试在地图中存储std :: string并收到以下错误 error: invalid initialization of reference of type ‘boost::any&’ from expression of type ‘std::string’

代码如下

#include "boost/any.hpp"
#include <iostream>
#include <map>

using namespace std;

map<string, boost::any> m;

void putObject(string name, boost::any& value)
{ m[name]= value; }

boost::any getObject(string name) { return m[name]; }

int main()
{
    string s = "a";
    cout << "Original Address: " << &s << endl;

    putObject(s, s);

    return 0;

}

0 个答案:

没有答案