Implicit Conversion and the Explicit Keyword in C++

Implicit Conversion and the Explicit Keyword in C++

The Cherno

6 лет назад

182,838 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Yang Paul
Yang Paul - 29.10.2023 17:38

Hi Cherno, when i use Entity a = "Cherno" it shows error "no visible conversion". so i change to Entity a = std:string("Cherno") it works. why in your video , Entity a = "Cherno" works.

Ответить
Tommy Snow
Tommy Snow - 11.10.2023 05:26

I finally get what the explict word before constuctor means, thank you

Ответить
reaper84
reaper84 - 11.07.2023 14:26

Great videos you did! Very condensed and right to the point.

Ответить
Rohan Zener
Rohan Zener - 21.06.2023 10:16

Does that keyword work for converting two different entities to each other?
Like a Cartestan point to a polar point, or vice versa.

Ответить
吴昊伦
吴昊伦 - 31.05.2023 10:14

I'd like to ask a question about the statement " Entity a = "Cherno" ". "Cherno" needs to be converted to string, and string needs another conversion to get Entity, so it totally needs two conversions to get Entity object from "Cherno", which is unacceptable in C++. But why this statement in the video can be compiled and run successfully? I've tried it on Visual Studio 2022, and the compiler does report an error. Actually, I have to rewrite the statement as " Entity a = std::string("Cherno") " to make it work.

Ответить
Sam
Sam - 29.04.2023 05:26

22 back then and you knew this much, wtf, you have a laptop in the womb or something, this makes me feel incredibly being in my 30s and only learning it now 😂

Ответить
show lee
show lee - 13.04.2023 13:08

Why did you slap me twice at the beginning🙁

Ответить
txgordo
txgordo - 02.02.2023 20:28

So, when executing PrintEntity(22), does it create an object? Or is the point that we can access the internals this way?

Ответить
Srisai Rayapudi
Srisai Rayapudi - 11.12.2022 20:57

Yo I always thought you were much older and I was like damn I can catch up to you but how the hell do you know so much at 22??? Super impressive. Cant believe you're doing insane at 27 now

Ответить
Serkan Öztürk
Serkan Öztürk - 09.11.2022 12:55

Personal Notes:
- Implicit conversion: for an object which has constructor Entity(int age), you can instantiate an object by saying Entity e = 44, it is allowable, c++ does the conversion itself

- explicit keyword prevents implicit conversion. For example, for a constructor explicit Entity(int age), you cannot create object by saying Entity age = 44

Ответить
Eugenia R
Eugenia R - 24.10.2022 23:25

you're a god of teaching C++

Ответить
ak44
ak44 - 21.10.2022 12:41

Thank you. This is the best video I've seen on this subject.

Ответить
minneelyyyy
minneelyyyy - 28.08.2022 04:35

rust developers: >:(

Ответить
Evgenii Sharaborin
Evgenii Sharaborin - 09.08.2022 13:40

Who knows what standard is it?
C++11?

Ответить
Shreenanda P
Shreenanda P - 30.04.2022 12:24

Wait..
Are you actually 22?

20 year old me :{ Imposter syndrome kicks in...

Ответить
Pavel Koprivec
Pavel Koprivec - 22.04.2022 10:44

Prevent unwanted implicit conversions with explcit keyword.

Ответить
Dead2098
Dead2098 - 09.04.2022 22:59

Wow. This is crazy, man. I never seen anyone do Entity b = 22. Where have you got all this from?

Ответить