c ++ const转换 [英] c++ const convert
本文介绍了c ++ const转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个函数:
bool isCirclePolygonIntersection(const Point*, const int*, const Point*,
const Point**, const int*);
,我想这样调用:
isCirclePolygonIntersection(p, &r, poly_coord, poly, &poly_size)
其中 poly
定义如下:
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
从我学到的是,你不能给 const
当函数期望一个非 const
参数时,函数的参数,但除此之外很好。
有没有人知道是什么问题?
谢谢。
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.
推荐答案
Parashift有一个很好的解释,为什么这是禁止的:
Parashift has a great explanation on why this is prohibited:
http:// www。 parashift.com/c++-faq-lite/const-correctness.html#faq-18.17
这篇关于c ++ const转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文