I'm using a library which has a draw function which takes a reference to a circle. I wish to call this function but I have a pointer to my circle object. Can I pass this pointed to object to the draw function? 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 like this
DoSth(*p);
I suggest that you should read a good C++ book. This is really fundamental stuff.
As long as pointer is not destroyed while the reference is still being used it is fine.
int *p = new int;
int &r = *p;
It would be easier if you'd supply some code of your problem. But basically it would work like this:
void func(Circle& circle) {
// do something
}
...
Circle *pCircle = new Circle();
func(*pCircle);