Похожие чаты

Class T{ public: T(int n){

std::cout<<n+n<<std::endl;
}
};
is T{5} a temporary object or an explicit constructor call?

16 ответов

8 просмотров
Ujjawal-Gupta Автор вопроса

Is this question has a curse or am too bad at asking questions?

There won't be any temporary as C++ 17 guarantees copy elision

Ujjawal-Gupta Автор вопроса
Manav | avoid unnecessary messaging me
There won't be any temporary as C++ 17 guarantees ...

Copy elision is avoiding unnecessary copying right? But what it has to do with object creation?

Ujjawal Gupta
Copy elision is avoiding unnecessary copying right...

Copy elision is avoiding unnecessary copy and move. There used to be issues when there was no guaranteed copy elision. For example, T t = f(); This type of expression would create a temporary which would be copied before C++11 afaik. Then later C++ standards gave you the ability to extend the lifetime of the temporaries for the sake of moving them. Now with guaranteed copy elision, the object is constructed in place rather than creating an unnecessarily copy

Ujjawal-Gupta Автор вопроса

So it's only an explicit call?

Ujjawal-Gupta Автор вопроса
Manav | avoid unnecessary messaging me
What do you mean by that?

Here they said that calls like vector(2) are explicit (page: 643)

Okay, I misunderstood what you meant to ask T{5}, can invoke the copy constructor but this can be elided. Gimme a moment so I can read the specific passage. Don't forget to specify the name of the book when you're asking here. It may be obvious to me that you're referring to Programming:Practice and principles using C++ by Bjarne Stroustup but it's not to other members.

Ujjawal Gupta
screenshot Here they said that calls like vector(2) are expli...

Here Bjarne is talking about implicit and explicit conversions. As for your question, T{5} will call the T(int) constructor directly so there's no disambiguity there.

Ujjawal-Gupta Автор вопроса
Ujjawal Gupta
it's an explicit call only?

I would say yes T{5} is you doing an explicit conversion, like T(5) T t = 5; This would be an implicit conversion

Manav | avoid unnecessary messaging me
Okay, I misunderstood what you meant to ask T{5},...

As for what I meant by eliding the copy construction T t = T{5}; The copy construction here will be elided. There will be only one call to T(int), you won't see T(T&)

Ujjawal-Gupta Автор вопроса
Ujjawal-Gupta Автор вопроса

Похожие вопросы

Обсуждают сегодня

А случайно нет ли в паскале штатной возможности передать указатель и количество туда где array of в качестве аргумента?
zamtmn
25
@LGCYMan @JustinKKW Q/A List 1. this part confuses me on #8: "From there, a bridge between erc20 LGXY and erc20 LGXY will be out once that swap is closed." does this mean ...
Sig | LGCY | BattleVerse L1 | BitWin
1
How do I get FrxEth? Need it to execute a contract
Abdullah $BTON
18
Did @Beeker really get banned? That's ridiculous. He's one of the few left here with half a brain and you might not always like his narrative @dgb_ycagel , but he often keeps ...
Leroy Gerrits
1
Maine b!nance se wazirx mein 200$ deposit kiya and usdt/inr pair mein sell krdiya 1% tds kata and maine inr withdrawal krliya , ab usme 30% tax dena hoga kya?
Xanime
12
Anyone here suffers from unexplained aural migraines, who would be up for talking for a bit? Doesn't *have* to be aural, but I am not asking about headaches, I mean actual mi...
Martin Rys
57
Добрый день ,ребята! А подскажите пожалуйста. Есть вот у меня макбук 13 2015 года,но на нём разбит экран,всё остальное в идеале. Стоит последняя МакОсь Монтерей 12. Можно ли ...
AR
7
async login(req: Request, res: Response, next: NextFunction): Promise<void> { try { const { errors, input } = await RequestValidator(LoginRequest, req.body...
. .
1
A couple thoughts from a random internet stranger: 1. If you want this project to gain traction you cannot keep being negative. If I just came here after finding out about Kd...
Eric Wild
46
Я тут за тем, чтобы задать вопрос, так как не знаю ассемблер, учу с/с++. Короче, насколько дорога операция перехода в функцию при ее вызове? Дело в том, что в с++ есть макросы...
Максим Рябцев
12
Карта сайта