This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: conversion problem with template, const with gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
- From: Claudio Bley <bley at CS dot uni-magdeburg dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 15 Jun 2004 10:06:48 +0200
- Subject: Re: conversion problem with template, const with gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
- References: <B5835E1CC5947D4F81BEAE6C6997398F023FEC66@etna.sim.umontreal.ca>
On Mon, Jun 14, 2004 at 04:04:18PM -0400, Roy Yves wrote:
> Hi:
Hello Roy,
>
> I am really puzzled with errors like the following:
>
> g++ -c pymat.cpp -o pymat.o -I/usr/local/matlab6p5/extern/include -I/usr/include/python2.2/numarray -I/usr/include/python2.2
> pymat.cpp: In function `mxArray* makeMxFromNumeric(const PyArrayObject*)':
> pymat.cpp:216: invalid conversion from `const maybelong*' to `int*'
> pymat.cpp:216: initializing argument 5 of `void copyNumeric2Mx(T*, int, int,
> double*, int*) [with T = char]'
>
> where copyNumeric2Mx is a template function:
>
> template <class T>
> void copyNumeric2Mx(T *pSrc, int pRows, int pCols, double *pDst, int *pStrides)
> { // ... }
>
> for each instantiated template function like in the following:
> case PyArray_CHAR:
> copyNumeric2Mx((char *)(pSrc->data), lRows, lCols, lR, pSrc->strides);
It seems pSrc->strides is a "pointer to const maybelong". Whatever kind of type `maybelong' may be,
C++ forbids to assign a constant object (via a pointer) to a variable as this would allow to change
the constant's value.
Either declare copyNumeric2Mx like that:
template <class T>
void copyNumeric2Mx(T *, int, int, double*, const int*);
^^^^^
(in case you're allowed to change the function's prototype)
OR you may "cast away" the object's constness:
copyNumeric2Mx((char *)(pSrc->data), lRows, lCols, lR, const_cast<maybelong*>(pSrc->strides));
--
Claudio