search

Home  >  Q&A  >  body text

c++ - 关于 throw 和拷贝构造

ringa_leeringa_lee2766 days ago541

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 13:53:18

    There is no problem with the first picture here and there is no need to copy it. Because the parameters you capture are of Except& type, not Except type.

    For the second one, it stands to reason that there should be no copying, because throw Except() throws a temporary Except object, and what is captured is its reference, so there is no need to construct another object. of.

    The second output result should be changed from catch(Except& e) to catch(Except e).

    throw Except() It should not only be able to compile in VS, but at least there will be no problem under g++4.8.

    reply
    0
  • Cancelreply