C++
vector<int>u;
u=vector<int>(3);
What kind of grammatical structure is it to substitute vector<int>(3)
for u
?
I understand that (3)
after vector<int>
represents the number of elements during vector class initialization, but I don't know who vector<int>(3)
is. Can you return the value to the right?In which document is the rule written?
Also,
u=*(new vector<int>(3));
What is the difference from ?
c++
I don't know who vector<int>(3)
is.
It means exactly as you see it.Constructor calls to size_type count
out of multiple overloads create std:vector<int>
with three elements.
What is the grammatical structure of replacing u
with vector<int>(3)
?
It does not mean that std::vector
also overloads operator=() with operator overload.
Because vector&other
, the right side value vector<int>(3)
is moved to the left side value u
.In addition, the right side value vector<int>(3)
is no longer used and is released by the destructor.
u=*(new vector<int>(3));
The same is true that the right side value *(new vector<int>(3))
is moved to the left side value u
.However, new vector<int>(3)
is only a pointer and is not released.You must explicitly delete
.
Add only the parts that are not explained
Is there a rule that writing vector<int>(3)
returns the object with the right side value?
Yes
Which document is it written in?
The official documentation will be ISO/IEC 14882 C++ language specification.Oira only has a very old ISO/IEC 14882:1998 and its translation, JIS X 3014:2003, but here's a quote from you.
3.10 Left and right values 6
(6) An expression having a temporary object resulting from a cast to a non-reference type shall be a right-hand value (this includes the case of explicit generation of an object using function notation)
544 PHP ssh2_scp_send fails to send files as intended
546 Who developed the "avformat-59.dll" that comes with FFmpeg?
679 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
543 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
524 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.