Похожие чаты

Class T{ public: T(int n){

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

16 ответов

22 просмотра
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
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 Автор вопроса

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта