| www.delorie.com/archives/browse.cgi | search |
| From: | Brian Sturk <bsturk AT nh DOT ultranet DOT com> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Compiler error. "Invalid types" int[int] |
| Date: | Sat, 13 Dec 1997 00:59:02 -0500 |
| Organization: | Contractor |
| Lines: | 38 |
| Message-ID: | <34922426.A0CC7E76@nh.ultranet.com> |
| NNTP-Posting-Host: | ninsun.nh.ultra.net |
| Mime-Version: | 1.0 |
| Cache-Post-Path: | ninsun.nh.ultra.net!unknown AT d7 DOT dial-4 DOT exr DOT nh DOT ultra DOT net |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
I'm trying to return a pointer to an array from a function and then
using it in my main program
I'm missing something really fundamental here...
i.e.
int* myFunc(...)
{
// int m_Array[...] is member of some class
for (int i = 0; i < SOME_NUMBER; i++)
m_Array[i] = i;
return m_Array;
}
I also tried casting the m_Array to int*
The compiler error is coming from trying to index the returned pointer
as if it were
an array name.
int* pArray = myFunc(...)
int nFirstInt = pArray[0];
This gives me the error.
I haven't tried indexing the returned pointer using pointer arithmetic
yet. I wanted to see if
this is possible. I thought it was but I guess I was wrong. Aren't
array names also pointers to first element of the array? I looked in
the DJGPP archives and this exact compiler problem was discussed but the
context was passing arrays *to* functions. Any help with this would be
greatly appreciated.
--
Curator of the Unofficial Homepage for Borland C++ Builder
http://www.nh.ultranet.com/~bsturk
'"HOL" The Hardware Obstruction Layer' The NTChrist
Whatever happened to Pong??? Frank Black, The Pixies
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |