Mail Archives: djgpp/1997/12/14/11:21:11

From: hgfernan AT usp DOT br
Message-Id: <>
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 


Please see the example below:

#include <iostream.h>

class TEST
    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.

Hilton Fernandes
email: hgfernan AT usp DOT br
www: (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