Pointer as Array reference

R

Ruediger Knoerig

In my current project I used templates to provide an
universial interface to vector objects. For this purpose I declared
two methods with an additional template argument:

template<class Vector> void transform(const Vector &x)
template<class Vector> void inv_transform(Vector &x)

Doing it this way I can use it on all data containers
providing index array access via []:

Transform<float> T;
valarray<float> x(16);
float data[16];
float stream[64];

T.transform(x); // works
T.transform(data); // works too
T.inv_transform(x); // works
T.inv_transform(&stream[32]); // error: no matching function for call to
`StreamWaveletTransform<float, HaarFilterBank>:: inv_transform(float (*
[])'
candidates are: void StreamWaveletTransform<T,
FilterBank>::inv_transform(Vector&) [with Vector = float (*)[], T = float,
FilterBank = HaarFilterBank]

The problem is that the compiler won't take a "float *"
for an "float *&". If I do this conversion expilitly I get:
"conversion to non-const reference type `float*&' from rvalue of type
`float*'".

Any suggestions? :-(
 
K

Karl Heinz Buchegger

Ruediger said:
The problem is that the compiler won't take a "float *"
for an "float *&". If I do this conversion expilitly I get:
"conversion to non-const reference type `float*&' from rvalue of type
`float*'".

Any suggestions? :-(

the epxression

&stream[32]

yields a temporary (the address of the element 32).
You are not allowed to bind a temporary to a non const reference.

template<class Vector> void inv_transform( const Vector &x)
*****
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,426
Latest member
MrMet

Latest Threads

Top