Implicit Conversion and the Explicit Keyword in C++

  Рет қаралды 182,117

The Cherno

The Cherno

6 жыл бұрын

Patreon ► / thecherno
Twitter ► / thecherno
Instagram ► / thecherno
Discord ► / discord
Series Playlist ► • C++
Gear I use:
-----------------
BEST laptop for programming! ► geni.us/pakTES
My FAVOURITE keyboard for programming! ► geni.us/zNhB
FAVOURITE monitors for programming! ► geni.us/Ig6KBq
MAIN Camera ► geni.us/t6xyDRO
MAIN Lens ► geni.us/xGoDWT
Second Camera ► geni.us/CYUQ
Microphone ► geni.us/wqO6g7K

Пікірлер: 258
@brunooliveirasoares7489
@brunooliveirasoares7489 4 жыл бұрын
22 years old and teaching like a war veteran. Glad my parents doesn't know you, so they can't compare =P
@jerfersonmatos28
@jerfersonmatos28 4 жыл бұрын
😂
@erwinschrodinger2320
@erwinschrodinger2320 3 жыл бұрын
Haha
@zes3813
@zes3813 3 жыл бұрын
no such thing as like veteran or not or ceomparex etc, cepuxyuax, say, do, can say, do any nmw and anys perfect
@emreeren7661
@emreeren7661 Жыл бұрын
@@zes3813 exactly
@lincolnwallace17
@lincolnwallace17 Жыл бұрын
Nice to see other brazilian around here! hahaha Tamo Junto!
@hokhyt
@hokhyt 4 жыл бұрын
My biggest take away from this is you were 22 and had the experience of a 32.
@user-sj6ku2fo6c
@user-sj6ku2fo6c 3 жыл бұрын
Maybe 52
@zes3813
@zes3813 3 жыл бұрын
wrgg, expx doesnt amtter
@13thxenos
@13thxenos 7 ай бұрын
I'm 33 and I have like a tenth of his experience, even though I dabbled in programming since I was 16.
@Cynokine
@Cynokine 6 жыл бұрын
We should make a tree for all the dependencies between the videos :D biggest tree ever
@peto348
@peto348 6 жыл бұрын
Are those dependences acyclic?
@anirudhsilverking5761
@anirudhsilverking5761 4 жыл бұрын
@@peto348 one could only hope
@muhammadtaimourafzal5285
@muhammadtaimourafzal5285 3 жыл бұрын
spoken like a true legend
@Artaxerxes.
@Artaxerxes. 3 жыл бұрын
@@peto348 They are. Else itd be just a graph
@rhodexa
@rhodexa 2 жыл бұрын
`#include "previousvideo.h"`
@vaecore
@vaecore 6 жыл бұрын
links here, links there, links fucking everywhere
@AgentM124
@AgentM124 6 жыл бұрын
well that will make killing ganon and saving princess zelda easy...
@saladgaming7146
@saladgaming7146 4 жыл бұрын
This has changed in the passing years, you now have to do Entity a = std::string("Cherno"); This is because of the same explanation at 3:46
@ferociousjuggler2668
@ferociousjuggler2668 3 жыл бұрын
I was wondering about this
@this_is_mac
@this_is_mac 3 жыл бұрын
"this" has changed?
@Dartz_Gone_Insane
@Dartz_Gone_Insane 3 жыл бұрын
this is not the case in my computer, maybe this is different for different architectures
@erwinschrodinger2320
@erwinschrodinger2320 3 жыл бұрын
@@Dartz_Gone_Insane maybe you are not using the most up to date version of C++
@pawelpow
@pawelpow 3 жыл бұрын
I still prefer to do this: Entity a = (std::string) “Cherno”;
@jamalnavarro3413
@jamalnavarro3413 4 жыл бұрын
I'm 14 years old and this stuff will differently help me in my future career.
@orvvro
@orvvro 4 жыл бұрын
keep on learning man!
@srijandhungana2102
@srijandhungana2102 3 жыл бұрын
same
@pranjalbajpai156
@pranjalbajpai156 2 жыл бұрын
get the hell out of here ..enjoy your age this is a mess don't peek here
@pinklady7184
@pinklady7184 6 жыл бұрын
I am glad that you are continuously doing tutorials in C++. Thanks for making them.
@reaper84
@reaper84 Жыл бұрын
Great videos you did! Very condensed and right to the point.
@kshitijkumar8799
@kshitijkumar8799 3 жыл бұрын
I have gone through a lot of channels on KZfaq for over-viewing C++ related content . Hands down, your channel is the most concise and easy to grasp one. I very much appreciate your rigor and desire to share knowledge. Kindly keep up the good work.
@user-gj7nd7rb4v
@user-gj7nd7rb4v 6 жыл бұрын
waving my arms around thank God you realized that love these tutorials great job and thank you
@srisairayapudi6074
@srisairayapudi6074 Жыл бұрын
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
@b1ueocean
@b1ueocean Жыл бұрын
His brain is full of information he is taking the time to learn and practice. It is impressive (especially for the high distraction social media, online video, square eyes world we are in today). When I was a kid, commercial game programmers were as young as 17, 19, 22, 25, etc. - self taught folks that put in the time and investment into what they loved - there wasn’t any internet, no mobile phones, in many countries national TV consisted of a handful of channels 😂 e.g. only 4 TV stations in the UK until year 2000 when Channel 5 came out. Sky satellite TV came into our home when I was 20 in ‘97. I was writing 2D graphics and games engines in C/C++ and 32-bit Intel Assembler at 15, by 18 doing my own basic 3D models and texture maps and getting them rendering via updated engines. When you didn’t have distractions, you decided how to spend your day and use your time. Same is true today but with far more discipline required 😳 You had a book if lucky, or a .txt programming manual file and just sat down and experimented until you got it. No StackOverflow (unless messing with recursion) No Google (or GHz either, 3Mhz to 66Mhz 640K to 4MB RAM) No access to other coders (even tougher to get hands on good reusable code to save you reinventing things you needed) Just man/woman, boy/girl and machine 😊 I knew guys that learnt to program without a computer at home - they lived in the after school computer clubs and neighbourhood libraries, getting all of the time with the machine they could get 🤷‍♂️ Learning is an amazing journey - no time like the present to get going on that journey. Oldest commercial programmer I know is 64 (PhD Electronics) his firmware and Embedded code helps to keep Boeing jets in the sky and operational when their electrical systems experience cascading failures 😊 Oldest hobbyist coder I know is 71 - writes Machine Learning models in Java to algorithmically trade European and Asian equity markets. He did some mainframe coding in his mid 20s before entering IT Sales. Started with Java and ML at 67 🧑🏻‍💻 Attitude • Mindset • Focus • Discipline all you need to set yourself apart - at any age!
@kanskejonasidag1
@kanskejonasidag1 6 жыл бұрын
"There will be a link in the descpription" - will it, though? ;)
@prateekkarn9277
@prateekkarn9277 3 жыл бұрын
no
@meow75714
@meow75714 3 жыл бұрын
Nice clear explanation. Good work.
@ak-ge4qc
@ak-ge4qc Жыл бұрын
Thank you. This is the best video I've seen on this subject.
@nickcui4567
@nickcui4567 6 жыл бұрын
Very nice tutorial. Thanks Cherno.
@donaldcsorny1487
@donaldcsorny1487 6 жыл бұрын
Awesome video, thanks a lot. I'll definitely be using your content in the future.
@gabgaby999
@gabgaby999 5 жыл бұрын
Thanks you ! It was very clear !
@Quancept
@Quancept 3 жыл бұрын
Thanks buddy! Helped a lot.
@mikicerise6250
@mikicerise6250 2 жыл бұрын
I'm currently digging my way out of a series of wrapper containers for a school project, whose iterators wrap other iterators that wrap other data structures, ultimately with as many as six levels of indirection and substantial use of implicit conversions, complete with conversion overloads, to const the damned things. At times I'm just genuinely amazed the thing compiles and runs at all and that I actually coded it myself. xD
@sridharkumar6088
@sridharkumar6088 2 жыл бұрын
Good video. Thanks for uploading!!
@monishkumardurairaj3038
@monishkumardurairaj3038 5 жыл бұрын
i tried a lot but i could not understand . why Entity e ="cherno"; works when printentity("cherno"); failed...... In the Entity e ="cherno"; also cherno is a const char arrray[7] so it must be first converted into std:: string and then into entity.two implicit conversions are needed. but how it works??? i could see in comments that some say Entity e ="cherno"; is simply Entity e =Entity("cherno"); and only one implicit conversion is needed for std:: string. if that is the case if i make the constructor as explicit . then Entity e=22; is simply Entity e=Entity(22); must work but it fails....
@adrianbaranowicz507
@adrianbaranowicz507 5 жыл бұрын
Quite a late reply but I've made some digging on this and the part where: Entity e = "cherno"; looks totally wrong to me and it should not compile at all. One can spot two implicit user-defined conversions happening here, 1) const char* -> std::string and 2) std::string -> Entity (see 'converting constructor'). Sidenote: std:string is NOT considered as 'build-in' type, while char is. From what I see, there is no much difference between the call to PrintEntity("cherno") and this - the same two implicit, user-defined conversions would be needed for it to work, while only a single one is possible to do (by standard) which results in compilation error here. I'm just installing Visual Studio to test it with its compiler but what we see on the video is only the Intellisense tips (or whatever) and not actual compilation output.
@anup.deshmukh
@anup.deshmukh 4 жыл бұрын
Entity a = "cherno" fail in my case But after doing Entity a = std::string("cherno") works
@skuldugery
@skuldugery 4 жыл бұрын
@Fernando Rosendo I tested it in VS 2019 and I got an error saying "no suitable constructor exists to convert from "const char [6]" to "Entity""
@skuldugery
@skuldugery 4 жыл бұрын
@Fernando Rosendo Probably because he didn't actually compile it. He only used Intellisense to check for Errors.
@explorerofworlds512
@explorerofworlds512 4 жыл бұрын
I hope this comment thread reaches most likes on the page. I know finding these comments helped me a lot and I hope it helps anyone else who was really confused by this. Thanks a lot you guys for getting to the bottom of this.
@Kodreanu23
@Kodreanu23 6 жыл бұрын
Great video, thanks!
@codysing8291
@codysing8291 6 жыл бұрын
Great job
@eugeniar7101
@eugeniar7101 Жыл бұрын
you're a god of teaching C++
@mohammedmarhnine8194
@mohammedmarhnine8194 2 жыл бұрын
you have a great introduction keep going
@Toccobass13
@Toccobass13 3 жыл бұрын
thank you sm man
@code-island
@code-island 4 ай бұрын
this channel is a masterpiece, this guy is a talented teacher and programmer, thanks for this in deep series free .
@ohaRega
@ohaRega 6 жыл бұрын
How are you only 22 and have so much experience? I'm 24, and yes, quite jelly. Anyway, keep it up!
@worsethanjoerogan8061
@worsethanjoerogan8061 6 жыл бұрын
Same I'm 24 and nowhere near this guy's level yet. They're teaching code in elementary school these days, next generation will be insane
@RmDIrSudoSu
@RmDIrSudoSu 4 жыл бұрын
He has many knowleadge for sure, but usualy when you're doing tutorial or course for your student, while you're preparing them, you take a lot of informations and learn a lot more stuff that you didn't knew and/or that you knew but forgot. But for sure having that kind of knowleadge at his age is really impressive.
@rajeng2453
@rajeng2453 4 жыл бұрын
The goal is not to compare ourselves with others, but to our own self from the day before.
@ammgnero
@ammgnero 4 жыл бұрын
Yeah i'm 22 too and no similar knowledge between him and me but the world is matter of chances i bet there is some random person in the world 12 or 13 years old but has even more knowledge.
@alex41693
@alex41693 4 жыл бұрын
@@ammgnero I am a professional C++ developer, 27 years old, and I am still here watching this video to learn from Cherno, he is much smarter than me :)
@michaelswahla4927
@michaelswahla4927 7 ай бұрын
1:43 you are now 28 years old as from 30/11/2023, time flys lol
@ammarassi7095
@ammarassi7095 4 жыл бұрын
You are 22 and worked in EA you must be sooo smart
@almicc
@almicc 6 жыл бұрын
I nearly spit out my drink when I saw you write *Entity a = "Cherno"* because I was laughing at how silly it looked. Coming from Java and C++ is constantly surprising me xD
@spacetime_wanderer
@spacetime_wanderer 5 жыл бұрын
Same here. And once you get C++ and look at Java, thankfully, you can still remember things in Java because of the way Java was designed. I feel it's better to learn C++ first and then Java though.
@monishkumardurairaj3038
@monishkumardurairaj3038 5 жыл бұрын
Hi almic, Entity a = "Cherno" ; doesn't work for me... when i tried it compiler throws error: conversion from 'const char [7]' to non-scalar type 'entity' requested. here is my code. #include #include using namespace std; class entity { public: int age; string name1; entity(const string& name):age(-1),name1(name) { } }; int main() { entity e2="cherno"; return 0; }
@michaeldifelice2313
@michaeldifelice2313 5 жыл бұрын
@@monishkumardurairaj3038 keep watching the video, he comments on this later. basically you would need to convert your const char * to a std::string to match the parameter for your .ctor. Try wrapping it in a call to the std::string() constructor first.
@sing759
@sing759 4 жыл бұрын
you learn assembly language (optional) then, learn C, then C++, then Java and C# ..finally learn python... you can see how it getting easier and easier and related to each other
@mrpedrobraga
@mrpedrobraga 4 жыл бұрын
String s = new String(); String t = "aajdkd";
@CalistheNick01
@CalistheNick01 4 жыл бұрын
Very informative
@exoticcoder5365
@exoticcoder5365 3 жыл бұрын
best explanation
@AM-ku9cw
@AM-ku9cw 2 жыл бұрын
Thank you very much :)
@raiyanreza9764
@raiyanreza9764 3 жыл бұрын
@0:02 "waving my arms around!" lol
@LucidStew
@LucidStew 6 жыл бұрын
In regards to your consistent use of const & in place of passing an argument by value/returning by value, are there/would there be instance(s) where you would pass by value/return by value rather than const reference?
@debaloychatterjee6892
@debaloychatterjee6892 2 жыл бұрын
The captions: My name is the *cheddar* _waving my arms around_
@advitiayanand5974
@advitiayanand5974 5 жыл бұрын
"Waving my arms around" XD
@freddy7304
@freddy7304 4 жыл бұрын
I just realized i can actually follow along with this video and understand everything just fine, it took me a while of watching your other tutorials and practice to get to this point. Im curious, if you were going to write code in your print function, how would you output the object. Using regular cout with the object name doesnt work.
@pengdu7751
@pengdu7751 2 жыл бұрын
blew my mind
@Davidgon100
@Davidgon100 5 жыл бұрын
Nice!
@bulentgercek
@bulentgercek 3 жыл бұрын
@The Cherno Man, I watched lots of tutorials about c++ and unreal engine tutorials with c++, and never and ever find someone like you. Your style is so fluent and on point. I am glad you are there man! Millions of thanks!
@gmfCoding
@gmfCoding 6 жыл бұрын
Cool, further more of my knowledge.
@TommySnow-uj7zn
@TommySnow-uj7zn 9 ай бұрын
I finally get what the explict word before constuctor means, thank you
@jul8803
@jul8803 22 күн бұрын
Quite an explicit video, as always.
@naoufal450
@naoufal450 6 жыл бұрын
Shit, I wasted so much of my lifetime.. u're awesome man. where did u learn and how did u get a job at EA at this age?
@cpthermes3703
@cpthermes3703 5 жыл бұрын
hey whats up guys my name is the cherno waving my arms around *hits laptop*
@0xbitbybit
@0xbitbybit Жыл бұрын
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 😂
@chainonsmanquants1630
@chainonsmanquants1630 3 жыл бұрын
Thanks
@Dartz_Gone_Insane
@Dartz_Gone_Insane 3 жыл бұрын
It is a good practice to avoid using the assignment operator and making use of implicit type conversion. Thanks for the video cherno.
@yanivgardi9028
@yanivgardi9028 4 жыл бұрын
Thanks for the great video. So, does it make any sense to use the explicit keyword in other places than constructor definition, like in regular methods, or in functions?
@neojw5011
@neojw5011 3 жыл бұрын
he said only with constructors
@machine0man
@machine0man 4 жыл бұрын
You are looking at camera lens and my 6 yr old brother is saying "Why he keeps looking at me" xoxo :p
@1Naif
@1Naif 6 жыл бұрын
WOW... i've learned something new, thanks. Also im 22 years old too ^_^
@neelimgoswami6336
@neelimgoswami6336 6 жыл бұрын
i have learnt everything new i am 13 years old
@rc5219
@rc5219 5 жыл бұрын
@@neelimgoswami6336 no one cares
@neelimgoswami6336
@neelimgoswami6336 5 жыл бұрын
@@rc5219 i didn't hope anyone would. you just wasted your time
@rc5219
@rc5219 5 жыл бұрын
@@neelimgoswami6336 I feel like saying the N word to u
@gerbillix3433
@gerbillix3433 5 жыл бұрын
rc521 lol what?
@Str33tF1ght1
@Str33tF1ght1 6 жыл бұрын
you can also have an explicit operator if you do it like this you only can use this operator with casting
@brycejohansen7114
@brycejohansen7114 2 жыл бұрын
You could say this is a rather _explicit_ way of explaining this
@jeffj7287
@jeffj7287 5 жыл бұрын
Hey Cherno I have a question. I know that's a old video but still. you do string& when you pass it in a function though you don't do int&. I know the difference between int& vs int though why most of the time we do string& and we don't do int&? Sorry if it is dumb.
@milan_shah
@milan_shah 3 жыл бұрын
5:50 if we have explicit Entity(const std::string& name) : m_Name(name), m_Age(-1) { } then PrintEntity(Entity("Cherno")) should fail, right? Because in this case, "Cherno" is `const char[ ]` not `std::string`, right? So, with the `explicit` keyword, conversion from `const char[ ]` to `std::string` should not happen, and eventually, the compiler should give an error, right? Because with the `explicit` keyword, `Entity` constructor either accepts `int` or `std::string` not `const char[ ]`. So, `Entity(std::string("Cherno"))` is the right way not `Entity("Cherno")`, correct? However, here, `Entity("Cherno")` is working without any error! Why?
@ajen003
@ajen003 6 жыл бұрын
255 views uint8_t approves
@1Naif
@1Naif 6 жыл бұрын
now its 512
@neelimgoswami6336
@neelimgoswami6336 6 жыл бұрын
now its 9426 which is quite less according to these videos
@potatolord7319
@potatolord7319 5 жыл бұрын
23,646
@greymind0072
@greymind0072 4 жыл бұрын
its 63k now
@LetaJIFAR
@LetaJIFAR 3 жыл бұрын
👉 73,929
@ebraheemalshapi5659
@ebraheemalshapi5659 3 жыл бұрын
No one does better than you cherno
@serkanozturk4217
@serkanozturk4217 Жыл бұрын
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
@steakiefrags1866
@steakiefrags1866 6 жыл бұрын
next time i put code on github, i make everything explicit before so nobody can destroy my readable code xD
@joshuatejero5617
@joshuatejero5617 3 жыл бұрын
What's the name of the object instance in "printEntity (22)" since your passing it as a reference??
@justasydefix6251
@justasydefix6251 3 жыл бұрын
This is where we can say, we passed 22 implicitly as an object to "PrintEntity()"
@tinkerer3954
@tinkerer3954 4 жыл бұрын
I realized you always wave your hands around at every intros
@EmyH-oo7mb
@EmyH-oo7mb 2 ай бұрын
what about constructer has the same int type(int grade):my_name("unknown"), my_grade(grade){}. In the main section, PrintEntity(14), it won't map to the grade correctly right? As there are multiple constructer parameters with same class, so PrintEquity(14) doesn't work.
@hakumen4252
@hakumen4252 6 жыл бұрын
One question, if you cant call printname("cherno") because "cherno" is not a string, why it is still valid for something like Entity a = "Cherno"?
@JaspreetSingh-fo2qe
@JaspreetSingh-fo2qe 6 жыл бұрын
YUE LI i had d same question...
@karmavil4034
@karmavil4034 6 жыл бұрын
Because it allows one implicit conversion level?
@JaspreetSingh-fo2qe
@JaspreetSingh-fo2qe 6 жыл бұрын
Federico Gallo i'll ask my teacher and confirm it
@swarnali9210
@swarnali9210 6 жыл бұрын
It does not work. Gives compiler error.
@jakobhellermann6974
@jakobhellermann6974 6 жыл бұрын
YUE LI you can implicitly convert *once*, so Entity a = ''Cherno'' ist basically Entity a = std::string(''Cherno''), which is okay, but printname(''cherno'') would have to be printname(Entity(std::string''Cherno'')), which is one conversion too much.
@GfastGao
@GfastGao 5 жыл бұрын
Just Come back again to say my feeling: C++ looks like a really serious language (It do, sure) as C, and through many bells & whistles like this "explicit" keyword push it to a level C eventually not easy to achive (but sure still possible) & make it task a little bit like javascript right now (Since "ES2015" out & gigantic Javascript Transcompiler & Framework & Tooling movements)
@shohamziner
@shohamziner 3 жыл бұрын
shouldn't be waving your arms like that in the presence of a cactus
@yanivgardi9028
@yanivgardi9028 4 жыл бұрын
by the way, the example in the video //Entity a = "Cherno"; doesn't compile as "Cherno" is not converted to a std::string but to const char[]. So how can you build it in the above example?
@Dead2098
@Dead2098 2 жыл бұрын
Wow. This is crazy, man. I never seen anyone do Entity b = 22. Where have you got all this from?
@b1ueocean
@b1ueocean Жыл бұрын
C++ compilers don’t implement everything - this has always been the case even in the 90s - and some introduce their own keywords and vendor-specific approaches to things - so for max portability things settle around a common subset vs. what is actually available/possible 👍
@Xxp0r
@Xxp0r 6 жыл бұрын
std::string name = "Rwar";
@vtgordo
@vtgordo Жыл бұрын
So, when executing PrintEntity(22), does it create an object? Or is the point that we can access the internals this way?
@ShivanshGupta51
@ShivanshGupta51 11 ай бұрын
Yes it creates an object for the scope of PrintEntity function
@showlee9176
@showlee9176 Жыл бұрын
Why did you slap me twice at the beginning🙁
@TheRojo387
@TheRojo387 Жыл бұрын
Does that keyword work for converting two different entities to each other? Like a Cartestan point to a polar point, or vice versa.
@thinkalvb
@thinkalvb 6 жыл бұрын
Turning 22 today - still learning how to write the main function properly (How ironic)
@bayesianmonk
@bayesianmonk 3 жыл бұрын
Nice videos, how do you quickly fix typos of m_age to m_Age?
@justasydefix6251
@justasydefix6251 3 жыл бұрын
This is where editting comes in handy
@nikoszervo
@nikoszervo 6 жыл бұрын
I've noticed that you use constant references to pass arguments into a method. In the beggining i was thinking wtf what's the point of a constant reference? But if i'm not mistaken its for oprimization? You pass the information that you need to a method without creating a copy of it on the stack and also you make sure not to change it? Am i right?
@Nnayz
@Nnayz 6 жыл бұрын
Yeah, u are right
@lionkor98
@lionkor98 5 жыл бұрын
i know this was a year ago but he is using const everywhere he can to guarantee that they are compatible with other functions which may *require* something to be const in order to be accepted.
@KostasOreopoulos
@KostasOreopoulos 5 жыл бұрын
You can also pass the return value of a function call directly as an argument f(y) => f(g(x)), which would not be possible if y is not declared as const
@lanik8163
@lanik8163 2 жыл бұрын
2:13 Yes they can. The only reason I'm here is to find out how to do the same in c++.
@Mariomm_marti
@Mariomm_marti Жыл бұрын
1:45 just saying, probably you know it but it's not the same thing to do A() and A = A(), one calls constructor + assignation and the other one constructor/copy constructor
@user-wd5zb5jl3i
@user-wd5zb5jl3i Жыл бұрын
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.
@zardingeorge7854
@zardingeorge7854 5 ай бұрын
I have the same doubt
@savansanghavi7465
@savansanghavi7465 5 жыл бұрын
When will you upload more videos
@alanmejia1330
@alanmejia1330 5 жыл бұрын
Wow I'm 22 too, but you're so good, probably I'm a potato
@pallavbhalla8493
@pallavbhalla8493 3 жыл бұрын
Query: What happens when you try to do implicit conversion where you have multiple member variables of the same datatype?
@TFDUDE123
@TFDUDE123 2 жыл бұрын
Experience of disgust from your peers
@LaraiFox
@LaraiFox 6 жыл бұрын
So maybe I'm missing something but I'm a little perplexed as to why { Entity a = "Cherno"; } works but { PrintEntity("Cherno"); } does not. You said the reason for the function failing was because the Cherno literal is of type const char[] and would need to be converted twice to be made into an Entity but doesn't it have to do that when instanciating an Entity too? I.e. surely { Entity a = "Cherno"; } has to convert the Cherno const char[] to an std::string object then convert that to an Entity, no? So why does that not fail?
@waceystewart2381
@waceystewart2381 6 жыл бұрын
There is a constructor that takes a string, so one conversion. The printEntity function needs an entity.
@vitaliipaprotskyi3815
@vitaliipaprotskyi3815 4 жыл бұрын
I have the same question. This line of code Entity a = "Cherno"; gives me an error in Visual Studio 2019 which says that there are no suitable constructor exists to convert from const char* [7] to Entity. And that makes sense to me. First we need to convert const char* to std::string and then std::string to Entity. Which is 2 conversions.
@Enigma1336
@Enigma1336 3 жыл бұрын
Why is it that Entity a = "Cherno"; is ok, but not PrintEntity("Cherno"); ? Don't they both need a double conversion from char[] to std::string to Entity?
@atata0215
@atata0215 5 жыл бұрын
also in implicit version Entity a="Cherno" hasn't work ,with error --> conversion from 'const char [5]' to non-scalar type @Cherno how it has works by you ?
@greymind0072
@greymind0072 4 жыл бұрын
try to compile Entity a="Cherno" , it will throw error, Why? because it does two implicit conversion, 1) converting const char array to std::string and 2)converting that to Entity type and calling that compiler . Why its working in video..? because probably he doesn't compiler it and just used intellisense plug-in to check
@zoriiginalx7544
@zoriiginalx7544 4 жыл бұрын
@@greymind0072 IIRC it's because he included the library and used an operator overload to convert const char* to string.
@shwetanksingh5438
@shwetanksingh5438 3 жыл бұрын
So I was trying to execute the same code and I noticed that if we don't use ------ const keyword ------ in the constructor taking string as parameter we get error ---- no suitable constructor exists to convert from "const char [7]" to "ie" ------- Can someone explain?
@bloodwolf8307
@bloodwolf8307 4 жыл бұрын
cool
@this_is_mac
@this_is_mac 3 жыл бұрын
you were 22 at that time and had experience at EA? how man?
@dx2002sg
@dx2002sg 3 жыл бұрын
Amazing, i asked how old are you in 2021 and you replied in a video made 2018. How cool is that?
@alessandrogaballo5767
@alessandrogaballo5767 6 жыл бұрын
Where's that video about casting? :)
@Skulltroxx
@Skulltroxx 2 жыл бұрын
dude what!? I thought he'd be over 25 atleast considering he's so proficient at C++ and has worked in EA and stuff.
@mikicerise6250
@mikicerise6250 2 жыл бұрын
He's made good choices and prioritized his education rather than wasting his youth as so many of us have done. Good for him!
@Raul11madrid1
@Raul11madrid1 6 жыл бұрын
Thanks now
@yangpaul1433
@yangpaul1433 8 ай бұрын
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.
@ezt1215
@ezt1215 8 ай бұрын
Compiler specific - some compilers will interpret this as two implicit conversions, namely from char[ ] to a string and then from string to an Entity. A bit confusing. For your compiler I would assume that PrintEntity ("Cherno") will also fail for the same reason.
@venugopalbv2069
@venugopalbv2069 6 жыл бұрын
Entity a = "Cherno" gives compilation error in Visual studio 2017. Why Implicit conversion doesn't work?
@esben181
@esben181 5 жыл бұрын
You must include in order to benefit from std::string's overloaded operator: operator const char* ()
@thomaslinssen1426
@thomaslinssen1426 4 жыл бұрын
So isn't 'int a(3);' more efficient than 'int a = 3; ' then? Because then there's no conversion right?
@strechatomas3072
@strechatomas3072 4 жыл бұрын
You're saying, that it can implicitly convert just once, but when you do `Entity e = "Cherno"`, it converts twice, doesn't it? "Cherno" from char[] to string and then string to the Entity object.
@__jan
@__jan 4 жыл бұрын
You're right. For some reason `Entity e = "Cherno"` didn't show an error for him, even though it is an error.
@soumyadeeppathak2901
@soumyadeeppathak2901 4 жыл бұрын
@@__jan it definitely shows for me.
@orvvro
@orvvro 4 жыл бұрын
No, the way I understand it, there is only one conversion, the string doesn't get converted to 'Entity', it's a member of 'Entity' already, the constructor takes a string as an argument.
@greymind0072
@greymind0072 4 жыл бұрын
@@__jan try to compile Entity a="Cherno" , it will throw error, Why? because it does two implicit conversion, 1) converting const char array to std::string and 2)converting that to Entity type and calling that compiler . Why its working in video..? because probably he doesn't compiler it and just used intellisense plug-in to check
@justasydefix6251
@justasydefix6251 3 жыл бұрын
@@__jan thats very simple, if you #include it will work
@mattgraves3709
@mattgraves3709 3 жыл бұрын
22 yrs old here? Waaaa? how long have you been writing code? You were freaking 11 when I started (I was 30) and better than I am lol. Youth plasticity
@avadhut325
@avadhut325 6 жыл бұрын
WOW !! you are just 1 year older than me ...and have much more coding experience.....
@fabionr4706
@fabionr4706 3 ай бұрын
I don't understand the difference in 03:24 where you declare Entity a (line 27) and call PrintEntity (line 25) since they are both being passed with a const char*, I'm trying to reproduce the code but for me it is failing for both cases, why for you it worked Entity a = "Cherno"
@Vermilicious
@Vermilicious 4 жыл бұрын
I don't like how they chose to rely on so much implicit behavior in C++. Instead of authors having to go to extra trouble to make better, more robust code, it should be the other way around. In this case, explicit should be default behavior, and if you don't want that you would use an implicit keyword.
OPERATORS and OPERATOR OVERLOADING in C++
12:44
The Cherno
Рет қаралды 365 М.
Casting in C++
13:25
The Cherno
Рет қаралды 182 М.
WHO LAUGHS LAST LAUGHS BEST 😎 #comedy
00:18
HaHaWhat
Рет қаралды 18 МЛН
Heartwarming: Stranger Saves Puppy from Hot Car #shorts
00:22
Fabiosa Best Lifehacks
Рет қаралды 21 МЛН
Мы никогда не были так напуганы!
00:15
Аришнев
Рет қаралды 6 МЛН
Was ist im Eis versteckt? 🧊 Coole Winter-Gadgets von Amazon
00:37
SMOL German
Рет қаралды 37 МЛН
Should you learn C++?? | Prime Reacts
20:29
ThePrimeTime
Рет қаралды 329 М.
How to CREATE/INSTANTIATE OBJECTS in C++
13:03
The Cherno
Рет қаралды 237 М.
Ключевое слово explicit в C++
11:45
Volodya Mozhenkov
Рет қаралды 7 М.
LEVY'S LUCK OF THE DRAW
16:32
GMHikaru
Рет қаралды 112 М.
the cleanest feature in C that you've probably never heard of
8:13
Low Level Learning
Рет қаралды 129 М.
The "auto" keyword in C++
17:04
The Cherno
Рет қаралды 200 М.
Rust's Alien Data Types 👽 Box, Rc, Arc
11:54
Code to the Moon
Рет қаралды 137 М.
Dynamic Arrays in C++ (std::vector)
14:14
The Cherno
Рет қаралды 373 М.
Conversion Operators in C++
19:56
The Cherno
Рет қаралды 36 М.
Function Pointers in C++
12:41
The Cherno
Рет қаралды 382 М.
WHO LAUGHS LAST LAUGHS BEST 😎 #comedy
00:18
HaHaWhat
Рет қаралды 18 МЛН