S
Steven T. Hatton
I believe it is technically possible to return a pointer to the first
element of an array. I can persuade the returned pointer to act like an
array, with some qualifications. I'm specifically interested in
multidimensional arrays.
It is often said that arrays and pointers are virtually identical. My
observations are that my (gcc) compiler knows the difference between T*, T
a1[9], and a2[3][3].
What I'm currently trying to do is to return a pointer (or reference) to an
array which was passed in as a container for the results of matrix
calculations taking two other matrices as arguments. It's the same concept
as using ostream& print(&ostream out, const objType& obj){ out << obj.data;
return out; }. I don't absolutely /need/ the functionality, but it would
be more intuitive to work with in some instances.
AFAIK, there is no way to specify an array return type. Whereas I can
specify 'ostream&', I cannot specify 'T[][dimensions]' as a return type. I
can use 'T*' as the return type and cast the returned array to T*. But
then it's not the same type as was passed in. Not to mention that it is
rather tricky playing with arrays at that level.
There are various reasons I would rather not use the stl containers. I can
create my own containers. AAMOF, that's what I'm doing. I don't need nor
even want iterators. Is wrapping the array in some kind of class type
object the only viable approach to passing arrays around?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
element of an array. I can persuade the returned pointer to act like an
array, with some qualifications. I'm specifically interested in
multidimensional arrays.
It is often said that arrays and pointers are virtually identical. My
observations are that my (gcc) compiler knows the difference between T*, T
a1[9], and a2[3][3].
What I'm currently trying to do is to return a pointer (or reference) to an
array which was passed in as a container for the results of matrix
calculations taking two other matrices as arguments. It's the same concept
as using ostream& print(&ostream out, const objType& obj){ out << obj.data;
return out; }. I don't absolutely /need/ the functionality, but it would
be more intuitive to work with in some instances.
AFAIK, there is no way to specify an array return type. Whereas I can
specify 'ostream&', I cannot specify 'T[][dimensions]' as a return type. I
can use 'T*' as the return type and cast the returned array to T*. But
then it's not the same type as was passed in. Not to mention that it is
rather tricky playing with arrays at that level.
There are various reasons I would rather not use the stl containers. I can
create my own containers. AAMOF, that's what I'm doing. I don't need nor
even want iterators. Is wrapping the array in some kind of class type
object the only viable approach to passing arrays around?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell