delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/14/11:21:11

From: hgfernan AT usp DOT br
Message-Id: <9712141619.AA18394@spider.uspnet.usp.br>
Comments: Authenticated sender is <hgfernan AT mail DOT iss DOT lcca DOT usp DOT br>
To: djgpp AT delorie DOT com, Brian Sturk <bsturk AT nh DOT ultranet DOT com>
Date: Sun, 14 Dec 1997 14:15:36 +0000
Mime-Version: 1.0
Subject: Re: Compiler error. "Invalid types" int[int]
Cc: "Fernandes, Hilton" <hgfernan AT usp DOT br>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019