Quantcast
Channel: Is it a good idea to typedef pointers? - Stack Overflow
Viewing all articles
Browse latest Browse all 16

Answer by Martin York for Is it a good idea to typedef pointers?

$
0
0

It (like so many answers) depends.

In C this is very common as you are trying to disguise that an object is a pointer. You are trying to imply that this is the object that all your functions manipulate (we know it is a pointer underneath but it represents the object you are manipulating).

MYDB   db = MYDBcreateDB("Plop://djdjdjjdjd");MYDBDoSomthingWithDB(db,5,6,7);CallLocalFuc(db); // if db is not a pointer things could be complicated.MYDBdestroyDB(db);

Underneath MYDB is probably a pointer at some object.

In C++ this is no longer required.
Mainly because we can pass things around by reference and the methods are incorporated into the class declaration.

MyDB   db("Plop://djdjdjjdjd");db.DoSomthingWithDB(5,6,7);CallLocalFuc(db);   // This time we can call be reference.db.destroyDB();     // Or let the destructor handle it.

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>