Take a look at this code:
struct Dummy
{
int bla;
int blabla;
char character;
Dummy (int b, int bb, char c)
: bla(b), blabla(bb), character(c)
{}
};
std::stack<Dummy> s;
Dummy dummy;
s.push(dummy);
s.emplace(dummy);
I do not see the difference between (1)and (2). I know that it emplace()is useful when you provide arguments for the constructor of the object to be added, for example:
s.emplace(1, 2, 'c');
but I do not know what the difference is when I described, because the and tags push(), and emplace()must refer to a local object dummyand create a new object using the copy ctor or something like that, you want to create push()any temporary objects in the process?
source
share