There are 3 ways a const can be used with a function: 1. const parameter; 2. const return value; 3. const function. Notes can be downloaded from: boqian.weebly.com
Пікірлер: 117
@thachnnguyen2 жыл бұрын
This person is among the best out there on youtube. Right straight to the point and no BS content to waste your time. Mostly comprehensive (if not all the time). Explanations succinct. Shows work and thought were put into making these tutorials, not just on the fly stuff that can be unorganized and wasting one's time. Keep up the good work.
@toth1982 Жыл бұрын
I totally agree. Very unique gem about C++.
@onkarmahajan41259 жыл бұрын
your Videos are really good and detail oriented ... I really appreciate your work - keep it up .. thank you
@sandeepkalwale77072 жыл бұрын
I agree 👍
@sandeepkalwale77072 жыл бұрын
Very clear and unique content. All important concepts covered through series. Thanks for your valuable contribution. Please prepare more playlist on C++.
@YM-vn2ts7 жыл бұрын
One of the best C++ videos on youtube. Thank you
@hearthrob4u11 жыл бұрын
Awesome videos !!!! Clear explanations better than going through books!
@drunkmadala5 жыл бұрын
I have bettling with this concept for so long, cheers!!!
@lazarbecic21992 жыл бұрын
Your work is greatly appreciated master Bo Qian~
@a1988ditya10 жыл бұрын
you are the best ...great set of c++ playlist ..really helpful ... \m/
@DeanWinchester84411 жыл бұрын
I like your videos. You explain it very good, very detailed. It's better than any book I've read so far.
@shvideo16 жыл бұрын
Excellent detailed video. Very educational. Thank you for taking the time to share your knowledge with the rest of the world.
@ВиталийВасилевич-р4л7 жыл бұрын
Your video is a perfect material which can help to learn programming as well as technical English. Thank you for your great job!!
@riwawaves9 ай бұрын
no wonder i was so confused, my professor introduced this week 2 into the course. tysm for the clear explanation!
@malharjajoo62377 жыл бұрын
you have a good clarity on separation of concerns.. good job
@plutonnico17335 жыл бұрын
MANY THANKS BO QIAN!! Subjects are very good, explanation too!
@toth1982 Жыл бұрын
8:00 This behavior that when we overload a member function with cost is something which can lead to unexpected errors imho. Suppose you writer of the class writes a const variant. It will run for non-const object. Then the writer of the class writes a non-const variant. From now on the new (non-const) function will be called for the same call. For me this can lead to unexpected errors.
@oualice94105 жыл бұрын
Clear logic with concise examples. Great video!
@00gamer210 жыл бұрын
I think "passive function" would be more appropriate name for const functions; constant variables keep the internal state of themselves constant though out. They are only worried about themselves; they don't care if they change the state of an external variable. Const functions differ in this respect. If const variables are children, then the functions are carers, always making sure the function and variables that are in their care are not hurt in any way. These const functions _care_ about others, you see. They are unsung heroes of this great paradigm of programming that we call "C++", because they CARE. _THEY CARE_. Calling these role-models "const functions" is an insult! They are _not_ children, _not_ those egotistic const variables playing it safe! To express my respect for these functions, I shall, from now on, call them: "mother functions". *THE TRUTH HAS BEEN SPOKEN*
@SkSafowan3 жыл бұрын
Man great detail and very easy to understand video. It's a shame that you stop uploading videos.
@МаратСаидов-н3ю7 жыл бұрын
Thank you for this course. Continue in the same way!
@priyanshipatel78047 жыл бұрын
indeed these videos are very comprehensive
@kbillore284 жыл бұрын
A function that takes const reference parameter can also be overloaded with a function which take reference parameter by passing const or non const parameter.
@azadalishah29662 ай бұрын
Have you tried that? Const parameter function can be called by passing non-const variable as well. I believe const-parameter function is called when literal value is passed as argument
@7thAttempt11 жыл бұрын
Excellent video! Thank you very much for sharing your C++ knowledge! :)
@pseudounknow55593 жыл бұрын
Nice explanation, usefull in 2021 !!!
@pdd3 Жыл бұрын
Bo Qian should be the president of Earth.
@edlugoa10 жыл бұрын
Awesome video setting all the possible occurrences!!!
@ghigopigo83173 ай бұрын
I just stumbled into this tutorial, i really like the style of it. My only worry is that it may not be up to date with modern c++ (?)
@zili83178 жыл бұрын
Your tutorial videos are really helpful! Thank you!
@jarusll6 жыл бұрын
Awesome bro, well explained. These are really useful
@isharthrastogi7826 жыл бұрын
exactly what i was looking for!
@FRChang-g2o Жыл бұрын
Thanks for sharing such a good tutorial!!
@azadalishah29665 жыл бұрын
At 5:55, non-const object d can call const function, does it mean that const function is called always by const or non-const object if no overloading non-const function?
@s.d.gentry13549 жыл бұрын
Very well done and informative.
@davidbohadana82749 жыл бұрын
It was amazing, thank you so mach for grate lesson :)
@xty0077 жыл бұрын
amazing lessons, thank you so much!
@alltheway992 жыл бұрын
5:26 name is not a temporary, is in fact a data member
@leelamanohar20018 жыл бұрын
Please find the sample program for the exercise: #include using namespace std; class Dog{ public: void set_age(const int &) { cout
@altafmahmud60957 жыл бұрын
After following your lecture on lvalue and rvalue reference, I understood that "void setAge(const int& a)" will be invoked by following two types of invocations: 1. Passing an rvalue parameter: Dog d; d.setAge(10); 2. Passing a const int parameter: const int n = 10; Dog d; d.setAge(n); And "void setAge(int& a)" will be invoked by any lvalue parameter: Dog d; int n = 10; d.setAge(n); Now my question is with following code: int n = 10; const int& m = n; Why this works? In this context "d.setAge(n)" should have been ambiguous, isn't it?
@4Seaofthoughts7 жыл бұрын
d.setAge(n) This calls setage(int &a),there is no ambiguity as n is lvalue.
@maximus541511 жыл бұрын
Great video, explained extremely well :]
@elephiant869610 жыл бұрын
Seriously good tutorial, thanks! :D
@stshsngh18 жыл бұрын
Great Work !!
@ResZRyou6 жыл бұрын
Thanks for sharing the material.
@bahalason9 жыл бұрын
Does it make sense to make a const function if the class doesn't have any private variables? Like a parser class for example. I could set every functions to const, but is there a need?
@raviraja055910 жыл бұрын
Very useful video...Thank you
@omersagsoz92619 жыл бұрын
do you have any tutorials, which contain the same topic but has pointers instead of references (e.g. const and pointers and functions)
@williamchamberlain22636 жыл бұрын
Nice summary
@BrianVandrian9 жыл бұрын
Thanx I was trying to understand when to use and not use consts this weekend, so I made every conceivable function I could think of (return parameters and input parameters and I made this error 3:20 nd was curious about it). I'm going through templates and they are explaining them using const (Bleh...)
@AmCanTech2 жыл бұрын
Thank you so much!!
@aakupsp8 жыл бұрын
Why we can change pointer member variables inside a const function?
@ninakoch17997 жыл бұрын
i love youuu! you saved my life!
@Bopek Жыл бұрын
genius, thank you
@aviadshalom669 жыл бұрын
I LOVE YOU
@layssi6 жыл бұрын
Best explanation ever
@slowthinker36910 жыл бұрын
Great tutorials. Subscribed.
@priyanshipatel78047 жыл бұрын
I want to ask,which one is better ide ,codeblocks or visual studio?
@Kromush19956 жыл бұрын
Got a question: when is good practice to return by const &? I know that by returning as const & you avoid calling the copy constructor on the object you return but also I've heard that it makes it thread unsafe, which is a little unclear to me why.
@gunjan94_4 жыл бұрын
If we return a reference to an object and the caller keeps the reference too long - meaning the object may clear up or it gets changed before the caller uses it - this can lead to undefined behaviour in your program or it can work perfectly well as well in case its intentional - depends on how you have designed the program. Note that even if you return copy of the object, you still need to make things thread safe incase multiple threads are involved - lock on the object whose member is being accessed.
@dmgkarthik9 жыл бұрын
can I invoke const functions from objects which are non constant ?
@Colonel1954Dz8 жыл бұрын
You can cast them when invoking the value: static_cast(d).printDogName(); // This would print dummyconst
@abdelaziz27883 жыл бұрын
where is the lvalue and rvalue video???
@foodlover31285 жыл бұрын
How you get this good in c++. You know everything
@riteshgupta59225 жыл бұрын
Hi Bo, I tried to get answer when which function get call setAge(const int& a) or setAge(int& a). I tried by passing const and non const value in both case setAge(const int& a) get called. However for the same case if have these function as global then const version called for const value and non-const one for non-const value. Please help me know why only const version get called for class and how it works if function are global?
@yogeshwalke18344 жыл бұрын
If you pass rvalue or const value to the setAge function then it will call setAge (const int&a) . If you pass non const lvalue to SetAge function then it will call SetAge(int& a)
@zahidkhankhan10 жыл бұрын
well explained. thanks for sharing. really appreciable..
@badmuthahubbard4 жыл бұрын
Thank you for this. I have a question: Why bother passing a const reference as an argument? I mean, if you can't change it inside the function, why not just pass it by value?
@Bing.W4 жыл бұрын
because it can be faster with const ref, where you save the copying.
@spyrex39882 жыл бұрын
for optimization
@ligzer019 жыл бұрын
keep up the good work!
@bougpan888 жыл бұрын
What is the ide that you use to make this c++ programming ? Thank you very much
@nikolaikalashnikov42537 жыл бұрын
He's using Netbeans IDE in this video.
@bougpan887 жыл бұрын
thank you very much
@mandaputtra3 жыл бұрын
Thanks!
@ragnarw.eliansson52997 жыл бұрын
Very good!
@mini_frank7 жыл бұрын
const referenced parameter will be invoked whent he caller is a const? regular reference parameter will be invoked when caller is a non-const? I am not sure, someone let me know if I am wrong.
@mini_frank6 жыл бұрын
seems like const ref parameter will be invoked when setAge(5), else regular ref parameter function.
@alditopalli953010 жыл бұрын
what compiler do you use i have visual studio 2012?
@madspace12345679 жыл бұрын
Code Art this is NetBeans on Windows w/ MinGW.
@BKJoe11610 жыл бұрын
Could there be a const non-member function, or is it a feature for member functions only
@cobblin_gock10 жыл бұрын
any function can be const
@gavinlangley84118 жыл бұрын
+kayvan Mansoorshahi a const type qualifier is not valid on non member function the point is what is not going to change? all global variables?
@mshri328611 жыл бұрын
what is the IDE or editor being used ?
@SAURAV1403406SAXENA6 жыл бұрын
age and name defaults to private right?
@yonizerbib9934 Жыл бұрын
thanks!!
@UltraAnalisis8 жыл бұрын
your voice sounds a bit difficult to understand, but you talk slow, that is good; thanks good video.
@maciejkowalski30197 жыл бұрын
Are you a native speaker? I come from Poland and I have no problems with his pronunciation.
@saturn7_dev Жыл бұрын
OMG - now I can see why I hate C++ so much. Its all so unnecessarily complex and confusing. I prefer to spend my brain energy on using simpler code that just works rather than on all these small details that can easily stuff you up - limiting how much actual useable code you write.
@huyvole97246 жыл бұрын
what relative beween double setAge and getName??
@martinnieva84846 жыл бұрын
What? Be more specific with your question.
@williamchamberlain22636 жыл бұрын
4:05 , 5:35,6:25,6:55
@yonizerbib9934 Жыл бұрын
so, a class attribut is never const ?
@jamesrockford26269 жыл бұрын
very nice
@junjieyue72816 ай бұрын
博主你好,你是中国人嘛,我最近也在学c++可不可以加个微信什么的,想向你学习一下😁
@AkhileshPratapShahi8 жыл бұрын
const function..... please do repeat once more
@sortysciaofiscia10 жыл бұрын
my mind: ............BLOOOWNN
@vlad_serg9 жыл бұрын
sortysciaofiscia Your mind have not seen rValue-reference yet)
@carlosamaral69174 жыл бұрын
Many people says wonders about this channel, but actually I find it quite confusing and not that helpful for a beginner! There are far better options around!
@SecurityManager6 жыл бұрын
const int& a == int a ?
@ldxyz-s1e7 жыл бұрын
3:12 6:33 7:03
@delpacho7 жыл бұрын
where is the answer to the question???
@RohitKumar-kr7ce6 жыл бұрын
d.setAge(static_cast(5)); will call void setAge(int& a) because 5 is casted into rvalue using && operator.
@azadalishah29666 жыл бұрын
5 is already rvalue, no need to cast
@azadalishah29666 жыл бұрын
setAge(40) will call setAge(const int& a) because literal 40 is rvalue and literal rvalue can’t be assigned to non-const lvalue reference.
@ShivaPrasad-hm5lk2 жыл бұрын
9yrs 😯
@ApoorvSaxena83 жыл бұрын
very usfeull
@DanHartwigMusic8 жыл бұрын
love your videos! but you name your dog dummy.... 🙁
@BoQianTheProgrammer11 жыл бұрын
Netbeans.
@jonnymcgrath4816 Жыл бұрын
Evil way to write codes
@deborah_chrysoprase9 жыл бұрын
why give your dog such a mean name :(
@virtuosisimo6 жыл бұрын
dogs are mean
@kejianshi91964 жыл бұрын
one of the conventions those old unix/bell lab people use. dummy variable. It's like _ in python : for _ in list