| |

VerySource

 Forgot password?
 Register
Search
Author: luyamin

Continue to Ask Copy Control

[Copy link]

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 United States

Post time: 2020-6-16 21:45:01
| Show all posts
Foo f = 100;
equal
Foo f(100);
Is that right?
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-17 14:45:01
| Show all posts
Foo f = 100;
equal
Foo f(100);
Is that right?
----------
no,
Foo f = 100; equivalent to the third case of my reprinted article
Foo f(100);//The second case of my reprinted article
Reply

Use magic Report

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-6-17 19:00:01
| Show all posts
tokillingme:

Oh, that might be a problem with g++.

But vc6 also has problems, Foo f = 100; This sentence may be directly interpreted as Foo f(100);, but according to the introduction in "C++ Primer", this should not be the case.
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-17 23:45:01
| Show all posts
But vc6 also has problems, Foo f = 100; This sentence may be directly interpreted as Foo f(100);, but according to the introduction in "C++ Primer", this should not be the case.
----------------
It shouldn’t be like this, see the third case of my reprinted article for details
----
3. T a = v;
....
The reason why it emphasizes semantics is because the standard says that this call can be optimized...
--------------
Reply

Use magic Report

1

Threads

39

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-6-18 09:15:01
| Show all posts
The upstairs is a translator or written by myself, messy.
Reply

Use magic Report

1

Threads

39

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-6-18 14:30:01
| Show all posts
I don't think this rule is necessary.

T v = 0;
T v(0);

The only difference is the explicit keyword.
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 Japan

Post time: 2020-6-19 11:15:01
| Show all posts
The upstairs is a translator or written by myself, messy.
-----------
I didn’t write it myself, I don’t have such a high level yet~-~
Reproduced others, where is the mess, that article puts the structure of the object
T a;
T a(v);
T a = v;
All kinds of situations have been mentioned, and it is a reference to the C++ standard. I feel that it is both complete and correct.
Reply

Use magic Report

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-8-19 17:15:02
| Show all posts
Found the answer by myself:

"C++ Primer" said:

The copy form of initialization is primarily supported for compatibility with C usage. When it can do so, the compiler is permitted (but not obligated) to skip the copy constructor and create the object directly.
The initialization of the copy form (ie, initialize with the = sign, I note) is mainly for compatibility with C usage. When this usage is supported, the compiler is allowed (but not forced) to skip the copy constructor and create the object directly.

I think this passage has already answered my question.

Thank you all upstairs, especiallykillingme.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list