I see a function definition that looks like this
ClassName::Read(myObjectClass &temp)
I’m trying to call it like this:
myObjectClass *myObj;
ClassName::Read(&myObj);
but that is incorrect. What is the proper way to call it? It needs to be of type myObjectClass&
As James correctly points out, the correct syntax is
*myObj. The point is that&myObjgives you the address ofmyObj, which has a type ofmyObjectClass**. You want instead to dereferencemyObjto get at the instance ofmyObjectClassto which it points, hence you use*.Incidentally, as it stands at the moment, using
*myObjwould cause undefined behaviour, sincemyObjitself has not been initialised. If you don’t need to dynamically allocate amyObjectClass, you might be better off just doing this:If dynamic allocation is a must, then you can do e.g.