Mail Archives: djgpp/1997/12/14/11:21:11
On Sat, 13 Dec 1997 00:59:02 -0500, Brian Sturk
<bsturk AT nh DOT ultranet DOT com> wrote
> I'm trying to return a pointer to an array from a function and then
> using it in my main program
Hi!
Please see the example below:
---------------------------------------------------------
#include <iostream.h>
class TEST
{
public:
int m_Array[10];
int* get_ptr (void) {return (m_Array);};
};
int main (void)
{
TEST t;
int *ptr = t.get_ptr ();
t.m_Array[0] = 2;
cout << "*ptr == " << *ptr << endl;
cout << "t.m_Array[0] == " << t.m_Array[0] << endl;
return (0);
}
---------------------------------------------------------
It prints:
---------------------------------------------------------
*ptr == 2
t.m_Array[0] == 2
---------------------------------------------------------
Pragmatic C++ programmers will disagree, but i think this is not good
OOP practice.
Regards,
++Hilton
-------------------
Hilton Fernandes
email: hgfernan AT usp DOT br
www: http://www.lsi.usp.br/~hilton.html (inactive)
M. Sc. Student of Parallel Distributed Applications
at Escola Politecnica (Polytechic School)
University of S. Paulo - Brazil
- Raw text -