开发者

What is main difference between creation of reference vs creation of object?

So a while ago I were playing with Boost.Extension example. They used

  std::map<std::string, factory<computer> > computers;
  computers.swap(types.get());

But when I started porting project from 开发者_开发知识库bjam to premake to visual studio project 2008 I found out that I can not use method they used for creating map. I always got Compiler Error C2512 on that line (actually on line 74 inside Boost.Extension type_map.hpp). So I used way of creating a link to a map:

map<string, factory<computer> >& computers(types.get());

(they used in some of there tutorials) and it all compiled. I am quite new to C++ and probably do not get alot.

So what is difference between creation of a map from link vs simple creation of a map, in this case and in general?

Update - full error message

Error 1 error C2512: boost::extensions::basic_type_map::type_map_convertible::type_holder: no appropriate default constructor available c:\users\avesta\downloads\extension-svn-source\boost\extension\type_map.hpp 74 Mltiple-Inheritance


The difference is that the second case doesn't create a map at all; it creates a reference to a map that already exists. types contains a map, and types.get() returns a reference to that map, which you use to initialise your own reference. If you modify the map using that reference, then you are modifying the map contained in types.

The first case does create an empty map; it then swaps it with the (presumably non-empty) map contained in types, leaving types empty afterwards. This will require more support from the various classes involved; some might need to be default constructible, swappable, and possibly copyable and/or assignable. The error code seems to indicate that one of the classes needs a public default constructor, but doesn't have one; it might help to diagnose the problem if you include the whole error message.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜