Advanced C++: Compiler Generated Functions
HTML-код
- Опубликовано: 28 ноя 2024
- Update on 9/22/12.
C++ compiler silently generates a number of code for you. This short video talks about the 4 functions that are generated by compiler. Class notes can be downloaded from my website: boqian.weebly.com
If code is not recognizable, increase RUclips video quality.
I am glad that you seem to indicate there is something good in my accent :) I grew up in China and came to US in my twenties, so that is my natural tongue. I tried hard but apparently not very successful to get rid of my accent.
Never get rid of your accent its cool. You are like the Jackie Chan of programming :) Your English is also quite good for someone of your heritage.
you are the Bruce Lee of C++
Mr.Qian,
These videos are excellent. I am a C programmer trying to learn C++. I just did not know details about C++ and these videos are very helpful.
Thank YOU!
Altaf
when destructor running, it first call data member's destructor, and then base class's destructor.
exactly! I think there is a typo in the slides becuase did meantion that the order is reversed in the destructor
That is correct. dynamic_cast can do that. For details, watch "All castings considered".
Very nice content.. Great source of learning. The way you teaches is very good. Please upload more videos of latest features in C++
best lessons ever. really. I know English little bit, but I've understood all of this
Nice comment about default constructor, I had the wrong impression that the default constructor is the one without argument, thanks for the clarification.
Thanks for your support.
Thank you so much for your tutorials, I really a fan of your way of teaching and explanation.
thanks so much!!!
Hello Mr Bo Qian,
I want to thank you for your response,I am thankfull also for yours videos,I will tell my friends about them.
With our regards from us(Daniel ,Mr Fortachin and Miss Shakira)
good to see you using VIM :)
The simplest solution is collar(string color="red"), give the default value to the parameter....
Thank you for all your videos, they are concise and simple to understand ( Aside, I like the way you say Bye bye :) )
Very helpful video... Minor comment... there is typo in the output of Dog class.....Output should be "Henry is destroyed". However o/p shows "distroied" :)
Hello Mr Bo Qian,I want to thank for your fast answer to my question,
Daniel
The destructor call order is written wrong ( at 1:00 time ), that should be reverse.
@Bo Qian, your videos are fantastic! One question about this one - you say that the compiler does not auto-generate the functions which aren't used (e.g. the copy constructor). In your example, around 10:10, the compiler suggests a candidate function of the dog's copy constructor - but why is that a candidate? You've not attempted to use that function, so it shouldn't have been generated, right? I must be missing something....
Member consts are static, and require program-wide initialization.
In begining of video, Dog class example, which has nothing, there is no need to generate default constructor. Why you think compiler will generate default constructor.
Hi Qian, thank you so much for the helpful video.
One question regarding the first example:
Why can't a reference member variable be copied in a compiler-generated copy assignment operator?
Reference variables can be reassigned, right? Also looks like if I have a custom copy assignment operator, I am able to copy the reference from rhs object to this object.
It's not the reassignment, but the initial assignment is never done, when the object is created.
A reference always need to be assigned to an lvalue when created.
In the example shown here, it's not assigned to any lvalue.
really good course!
One question :- if the class has const or reference member,then as explained copy constructor would not be provided by compiler.
But in case there are multiple members like:-
class B;
class A{
int a;
const int b;
B &ref;
static int x;
};
So in this case apart from const and reference variables, there are other variables too, so still compiler wont generate the copy constructor.
And in case we want to write our own assignment operator, how should we write it, please share your opinion.
Thanks in advance!!
Hi Bo. Can I ask you a question? If the compiler doesn't generate a move constructor, then what will happen when I use a rvalue to construct an instance whose class has no move constructor defined? Does it still use the copy constructor?
Also, when you change m_name in Dog class as string & , the constructor initializer list need to be written.
Default constructor written will not work
In your example, you said the compiler only generated copy constructor when main function is using it. But if the class is in a seperate file as in class library, and they compile seperately, how did the complile if they are used or not?
Yes It is Arturo(Daniel Arturo) yesterday you responded to me and I have another question that I am stuck with ...".... A cast may be used to convert a base-class pointer to a derived-class pointer.."
Is it a False statement ?
as I explained I am trying to learn programming from a book and this book has multiple choice question,
Thank you very much ,
Daniel Arturo.
I am going to watch this whole series and report back
hi Quian ,
i was wondering if c++ 11 has already covered drawback , so do we have seperate tutorial for c++ 11 ?
Why isn't copy constructor created by compiler in the first example? I thought it will be generated when dog2 = dog1? thanks!
awesome videoo...
Thank you for the lecture :)
I love you!
At 10:00, why copy constructor of dog generated when it’s not used? U said at 7:25 that no default functions r not generated if not used?
Much Thanks. I can't say that enough : ) Very smart and helpful. I like the (slight) accent.
Grt explanation
but isnt a constructor with parameters is called a parameterized constructor
?& can someone please explain me more thouroghly why the code is not compiling when he changes String to String
thanks!
reference and const member is not copy assignable the copy assginment operator will be deleted in this case
but they are copy constructable in normal cases
when copy constructed const member will be a different member for new obj , but references will still be the same reference;
are you using vim text editor?
I f I could ask you another question please?
Daniel
what about move constructor?
This is C++98. Look for "Modern C++" for 11.
what is "operator=(const dog& rhs)" what does this "operator" do ?
It might be too late but that is an overloaded function for the assignment operator ('=').
Ideally it assigns your (this) object to the object on the right hand side thats why its called rhs.
0:29
2:41
4:07
it also generates dog.eat()
LOL why
@@MustaWizard it's in the new standard. look it up.
@@Galal0110 XDDDDDD
@@MustaWizard :D
8:16
watch at 1.25x speed... Thank me later !!
Are you faking that accent?