I am using a library with a draw function that references a circle. I want to call this function, but I have a pointer to a circle object. Can I pass this to an object on a drawing object? If not, why not?
Thanks,
Barry
Yes, you can.
You have this function
void DoSth(/*const*/Circle& c) { /// }
You have this pointer
/*const*/ Circle* p = /*...*/;
You call it
DoSth(*p);
I suggest you read a good book in C ++ . This is truly fundamental material.
It would be easier if you put some code for your problem. But basically it will work as follows:
void func(Circle& circle) { // do something } ... Circle *pCircle = new Circle(); func(*pCircle);
As long as the pointer is not destroyed, while the link is still in use, this is normal.
int *p = new int; int &r = *p;
Yes, you can just dereference a pointer, for example:
void functionToCall(Circle &circle); //in your code: Circle *circle = new Circle(); functionToCall(*circle);