Is pointer to class a good technique in c++ | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 3

Is pointer to class a good technique in c++

Hii, today I have learnt that a pointer to class works same as using an object to acess members. So I got a doubt if they both accesses variable but in a different way. Then what would be the reason for having two different things performing similar work. In a nutshell my doubt is, using a pointer object to access class members faster than using a normal object to access class members.

10th Apr 2021, 9:23 AM
Sreenesh
Sreenesh - avatar
2 ответов
+ 3
There is no performance difference. You will likely use pointer to class to practice polymorphism, which is a main concept of OOP and you can use pointers to do it. On the other hand, pointer to class is basically pointer to variables, just a normal pointer. You might also encounter pointers if you use C libraries. Since there isn't reference in C, there are lots of needs to pass pointers to functions in order to modify the arguments (kind of off-topic, but it's worth to mention).
10th Apr 2021, 10:08 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Hello
14th Mar 2023, 2:57 PM
Shyam Sajjan
Shyam Sajjan - avatar