Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ const convert [duplicate]

Possible Duplicate:
why isnt it legal to convert (pointer to pointer to non-const) to a (pointer to pointer to a const)

I have a function:

bool isCirclePolygonIntersection(const Point*, const int*, const Point*,
                                 const Point**, const int*);

and I'm trying to call it like this:

isCirclePolygonIntersection(p, &r, poly_coord, poly, &poly_size)

where poly defined like this:

Point** poly = new Point*[poly_size];

and there is a compiler error when I'm trying to compile it:

error C2664: 'isCirclePolygonIntersection' : cannot convert parameter 4 from 'Point **' to 'const Point **'
1>          Conversion loses qualifiers

from what I've learned is that you cannot give const argument to function when a function expects a non const argument, but it's fine otherwise. Does anyone knows what is the problem?? Thanks.

like image 736
Vladp Avatar asked Aug 18 '11 14:08

Vladp


1 Answers

You're correct; you can implicitly convert a T * to a const T *. However, you cannot implicitly convert a T ** to a const T **. See this from the C FAQ: http://c-faq.com/ansi/constmismatch.html.

like image 185
Oliver Charlesworth Avatar answered Sep 30 '22 12:09

Oliver Charlesworth