I have gone through a lot of channels on TH-cam 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.
Feels_bad_man 😂 I'm having to shift to a cpp proprietary game engine and I'm trying to prepare as much as possible for it. I never really used cpp at work and my uni attempts with it are best forgotten. Him knowing all this at 22 though is more down the fact he's both gifted and hard working rather than the rest of us being complete lazy morons... I hope 😅
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
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!
@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!
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
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....
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.
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.
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
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.
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; }
@@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.
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
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?
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
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 😂
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.
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.
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.
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"
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.
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.
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.
@@__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
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?
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.
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.
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?
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.
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?
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.
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
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
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 👍
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?
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.
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.
@@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 :)
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?
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)
The example with the const char* is incorrect. The reason it doesnt work is because there is an implicit conversion, not because there are two. Even if you passed a std::string instead of a const char*, it would work. Try and see. It is a pretty good video though. Thanks.
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?
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?
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.
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 ?
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
write your own compiler, but it's kind of difficult, cause it wouldn't know what intermediate step to use. I mean try convert German to English, pretty easy. you can convert from German... to what? English... implicit right. But now you want to convert from Spanish to French. direct conversion doesn't exist... how would the system know to convert to english first and then to french. maybe there's another language it should convert to, or maybe there is no possible conversion. its just messy. just like this comment.
22 years old and teaching like a war veteran.
Glad my parents doesn't know you, so they can't compare =P
😂
Haha
no such thing as like veteran or not or ceomparex etc, cepuxyuax, say, do, can say, do any nmw and anys perfect
@@zes3813 exactly
Nice to see other brazilian around here! hahaha
Tamo Junto!
We should make a tree for all the dependencies between the videos :D biggest tree ever
Are those dependences acyclic?
@@peto348 one could only hope
spoken like a true legend
@@peto348 They are. Else itd be just a graph
`#include "previousvideo.h"`
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
I was wondering about this
"this" has changed?
this is not the case in my computer, maybe this is different for different architectures
@@Dartz_Gone_Insane maybe you are not using the most up to date version of C++
I still prefer to do this: Entity a = (std::string) “Cherno”;
I have gone through a lot of channels on TH-cam 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.
I am glad that you are continuously doing tutorials in C++. Thanks for making them.
My biggest take away from this is you were 22 and had the experience of a 32.
Maybe 52
wrgg, expx doesnt amtter
I'm 33 and I have like a tenth of his experience, even though I dabbled in programming since I was 16.
Feels_bad_man 😂 I'm having to shift to a cpp proprietary game engine and I'm trying to prepare as much as possible for it. I never really used cpp at work and my uni attempts with it are best forgotten. Him knowing all this at 22 though is more down the fact he's both gifted and hard working rather than the rest of us being complete lazy morons... I hope 😅
1:43 you are now 28 years old as from 30/11/2023, time flys lol
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
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!
waving my arms around thank God you realized that
love these tutorials great job and thank you
I'm 14 years old and this stuff will differently help me in my future career.
keep on learning man!
same
get the hell out of here ..enjoy your age this is a mess don't peek here
@@pranjalbajpai156 Calm down sister
you're a god of teaching C++
links here, links there, links fucking everywhere
well that will make killing ganon and saving princess zelda easy...
Great videos you did! Very condensed and right to the point.
this channel is a masterpiece, this guy is a talented teacher and programmer, thanks for this in deep series free .
@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!
If you haven't been slapped within the first second of watching the Cherno it's not worth it.
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
Thank you. This is the best video I've seen on this subject.
"There will be a link in the descpription" - will it, though? ;)
no
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....
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.
Entity a = "cherno" fail in my case
But after doing
Entity a = std::string("cherno") works
@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""
@Fernando Rosendo Probably because he didn't actually compile it. He only used Intellisense to check for Errors.
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.
The captions: My name is the *cheddar* _waving my arms around_
Nice clear explanation. Good work.
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
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.
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;
}
@@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.
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
String s = new String();
String t = "aajdkd";
@0:02 "waving my arms around!" lol
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?
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
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 😂
Awesome video, thanks a lot. I'll definitely be using your content in the future.
hey whats up guys my name is the cherno waving my arms around *hits laptop*
I finally get what the explict word before constuctor means, thank you
"Waving my arms around" XD
best explanation
Very nice tutorial. Thanks Cherno.
blew my mind
Great job
Good video. Thanks for uploading!!
Thanks buddy! Helped a lot.
you have a great introduction keep going
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.
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.
Quite an explicit video, as always.
thank you sm man
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.
I have the same doubt
did you get any answer to this ??
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"
Thanks you ! It was very clear !
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"?
YUE LI i had d same question...
Because it allows one implicit conversion level?
Federico Gallo i'll ask my teacher and confirm it
It does not work. Gives compiler error.
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.
you can also have an explicit operator if you do it like this you only can use this operator with casting
god u r a genius
You could say this is a rather _explicit_ way of explaining this
Thanks
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?
Great video, thanks!
Thank you very much :)
WOW... i've learned something new, thanks.
Also im 22 years old too ^_^
i have learnt everything new i am 13 years old
@@neelimgoswami6336 no one cares
@@rc5219 i didn't hope anyone would. you just wasted your time
@@neelimgoswami6336 I feel like saying the N word to u
rc521 lol what?
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.
You're right. For some reason `Entity e = "Cherno"` didn't show an error for him, even though it is an error.
@@__jan it definitely shows for me.
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.
@@__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
@@__jan thats very simple, if you #include it will work
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?
There is a constructor that takes a string, so one conversion. The printEntity function needs an entity.
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.
You are looking at camera lens and my 6 yr old brother is saying "Why he keeps looking at me" xoxo :p
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.
2:08 Entity a = "Cherno"; ==> error: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive]
However, you can do this::
String roger("Roger");
Entity a = roger;
printEntity(a);
or
Entity a = String("Roger");
printEntity(a);
next time i put code on github, i make everything explicit before so nobody can destroy my readable code xD
Query: What happens when you try to do implicit conversion where you have multiple member variables of the same datatype?
Experience of disgust from your peers
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?
hey whats up guys my name is the cherno waving my wands around 💀
No one does better than you cherno
Very informative
2:13 Yes they can. The only reason I'm here is to find out how to do the same in c++.
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.
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?
Yeah, u are right
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.
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
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
Wow. This is crazy, man. I never seen anyone do Entity b = 22. Where have you got all this from?
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 👍
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?
How are you only 22 and have so much experience? I'm 24, and yes, quite jelly.
Anyway, keep it up!
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
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.
The goal is not to compare ourselves with others, but to our own self from the day before.
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.
@@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 :)
Nice!
Does that keyword work for converting two different entities to each other?
Like a Cartestan point to a polar point, or vice versa.
So isn't 'int a(3);' more efficient than 'int a = 3; ' then? Because then there's no conversion right?
What's the name of the object instance in "printEntity (22)" since your passing it as a reference??
This is where we can say, we passed 22 implicitly as an object to "PrintEntity()"
Cool, further more of my knowledge.
Why does he use multiple constructors? What’s the advantage of it?
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?
he said only with constructors
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)
The example with the const char* is incorrect. The reason it doesnt work is because there is an implicit conversion, not because there are two. Even if you passed a std::string instead of a const char*, it would work. Try and see. It is a pretty good video though. Thanks.
It is a good practice to avoid using the assignment operator and making use of implicit type conversion. Thanks for the video cherno.
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?
255 views
uint8_t approves
now its 512
now its 9426 which is quite less according to these videos
23,646
its 63k now
👉 73,929
So, when executing PrintEntity(22), does it create an object? Or is the point that we can access the internals this way?
Yes it creates an object for the scope of PrintEntity function
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?
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.
Turning 22 today - still learning how to write the main function properly (How ironic)
Nice videos, how do you quickly fix typos of m_age to m_Age?
This is where editting comes in handy
Entity a = "Cherno" gives compilation error in Visual studio 2017. Why Implicit conversion doesn't work?
You must include in order to benefit from std::string's overloaded operator: operator const char* ()
shouldn't be waving your arms like that in the presence of a cactus
Implicit and explicit is not automatic. Like at 2:00
you were 22 at that time and had experience at EA? how man?
When will you upload more videos
Why did you slap me twice at the beginning🙁
I realized you always wave your hands around at every intros
You are 22 and worked in EA you must be sooo smart
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 ?
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
@@greymind0072 IIRC it's because he included the library and used an operator overload to convert const char* to string.
Where's that video about casting? :)
Wow I'm 22 too, but you're so good, probably I'm a potato
Is there a way to allow the compiler to do more than 1 implicit conversation?
write your own compiler, but it's kind of difficult, cause it wouldn't know what intermediate step to use. I mean try convert German to English, pretty easy.
you can convert from German... to what? English... implicit right.
But now you want to convert from Spanish to French. direct conversion doesn't exist...
how would the system know to convert to english first and then to french. maybe there's another language it should convert to, or maybe there is no possible conversion. its just messy. just like this comment.
No. Explictly cast it instead.