Nice, but a bit incomplete. Pointers are needed for: * Accessing heap memory * Datastructures that make use of null-pointers like linked lists or trees * Functions or datastructures that come from libraries that demand the use of pointers
We can also access heap memory with reference. Base& baseRef_B = *(new Base()); baseRef_B.print(); Base& baseRef_D = *(new Derived()); baseRef_D.print(); Please let me know if there are any drawbacks. Thanks.
4:16. I tried achieving it in the *main* function creating an object on *heap* and it works. *Any drawbacks or risks in this*? Base& baseRef_B = *(new Base()); baseRef_B.print(); Base& baseRef_D = *(new Derived()); baseRef_D.print(); Thanks.
Just want to ask we can store reference of derived class to base class and type caste it later when needed. What is better? Storing it as a reference and typecasting it. or Storing it as a pointer and typecasting it. or its the same and we can choose anyone?
@@nithyanarayan8080 I am also searching answer for the same question for looooong, what I see is, reference is safe..it ensure the data is valid..pointer doesnt ensure this..it can be NULL or invalid..
It is safe to go up from derived class 2 base class but if you are coming from base class to derived class then you should know that base was once a derived then only you can convert.
Just want to ask we can store reference of derived class to base class and type caste it later when needed. What is better? Storing it as a reference and typecasting it. or Storing it as a pointer and typecasting it.
If you ask industries are heavily using pointer. Pointers give more functionality than Ref, i mean ref have some restriction which pointer don't. So that's y pointer is heavily used. There can be other reason too, but i don't remember right now.
Nice, but a bit incomplete. Pointers are needed for:
* Accessing heap memory
* Datastructures that make use of null-pointers like linked lists or trees
* Functions or datastructures that come from libraries that demand the use of pointers
We can also access heap memory with reference.
Base& baseRef_B = *(new Base());
baseRef_B.print();
Base& baseRef_D = *(new Derived());
baseRef_D.print();
Please let me know if there are any drawbacks.
Thanks.
He is covering your second point though. The third one is kind of obvious don't you think? :D
Good video as always! Thank you and keep the good job!
+Ady2xp thanks dude.
Great video with infos. Keep it up.
Thanks for appropriation!
what is the main difference between the upcasting with reference to avoid slicing and run time polymorphism?
4:16. I tried achieving it in the *main* function creating an object on *heap* and it works.
*Any drawbacks or risks in this*?
Base& baseRef_B = *(new Base());
baseRef_B.print();
Base& baseRef_D = *(new Derived());
baseRef_D.print();
Thanks.
Just want to ask we can store reference of derived class to base class and type caste it later when needed. What is better? Storing it as a reference and typecasting it. or Storing it as a pointer and typecasting it. or its the same and we can choose anyone?
Thankyou… this was my last question about pointers finally answered
Glad i could help
Why its an error to use pointer in copy constructor?
show me your code.
#include
#include
using namespace std;
class base{
int x;
public:
base(int x1):x(x1){
;
}
base(const base &o){
x=o.x;
}
void print(){
cout
I don't seeany problem in this code can you tell me where the actual problem is?
My question is why we don't use pointer in copy constructor instead of reference?
@@nithyanarayan8080 I am also searching answer for the same question for looooong,
what I see is, reference is safe..it ensure the data is valid..pointer doesnt ensure this..it can be NULL or invalid..
very knowledge rich videos
form where did you study all this ?
i want to learn more
Can anyone please explain me copy constructor point
can we type caste base class reference to derived class??
It is safe to go up from derived class 2 base class but if you are coming from base class to derived class then you should know that base was once a derived then only you can convert.
@@CppNuts Thank you so much.
Just want to ask we can store reference of derived class to base class and type caste it later when needed. What is better? Storing it as a reference and typecasting it. or Storing it as a pointer and typecasting it.
If you ask industries are heavily using pointer.
Pointers give more functionality than Ref, i mean ref have some restriction which pointer don't.
So that's y pointer is heavily used.
There can be other reason too, but i don't remember right now.
Good Video
Thanks..
Sooper !!!!
Thanks man!!