search

Home  >  Q&A  >  body text

c++ - 创建新map对象问题

在《c++ primer》练习11.7中,当指定的家庭不存在时有一段代码如下:

families[family]=vector<string>();

这段代码最后一个括号作用是嘛啊- - 是哪一部分的知识呢??

阿神阿神2773 days ago424

reply all(2)I'll reply

  • 阿神

    阿神2017-04-17 14:35:55

    vector<string> represents a type
    vector<string>() represents a (temporary) variable created by this type (equivalent to directly calling the constructor, but here a parameterless constructor is called, thus creating an anonymous temporary variable)

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 14:35:55

    Call the default constructor of vector<string> to generate a vector object.
    For example, there is a class A. Yes, A a = A(); is possible. This object is not new, so it is on the stack.

    reply
    0
  • Cancelreply