Комментарии:
best Explanation - THANK u
ОтветитьVery useful
ОтветитьThanks for these videos. I have a question about when to use a copy constructor and when to overload the assignment operator. Is the difference that you use a copy constructor when you are going to initialize a new instance of the class with the values of an existing instance of that class and you override the assignment operator when you are making one existing instance of a class equal to another existing instance of that class?
ОтветитьThank you for the nice video.
I have 2 questions:
1: If i leave out the copy constructor the code works without error, but the values seem to be garbage. My guess would be that the constructor just gets skipped. But creating an empty class c: Foo f(5), g(6), h(8), c(); seems like weird behaviour. (Warning that empty paranteses where disambiguated as a function declaration). Which leads me to think that there is no way to skip the constructor. Would be nice if you could provide a short explanation.
2: If i add the following line in the copy constructor: 'std::cout << "inside constuctor" << std::endl;' at the assignment 'f=g;' it gets called twice. Why does this happen? It should only return 1 copy.
Thanks so much for explaining the logic behind how the assignment overload is constructed: thinking of it as a function really helps in understanding the process.
A great video, as always.