🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.mac.programmer.help
3 messages
3 total messages Started by Jeffery R. Price Thu, 02 Nov 1995 23:15
C++ - How to alter non-static, private array with a private member function?
#2
Author: Jeffery R. Price
Date: Thu, 02 Nov 1995 23:15
17 lines
1130 bytes
I am using CW7 and am relatively new to C++. I have a class which has a
private data member declared as:
   int Reg[6];

I have a private member function which I want to change the contents of
Reg[6]. If I do not declare Reg[6] as static, CW7 gives me errors anywhere
I try to alter Reg[i] in my member function - saying "Illegal use of a
non-static data member".

If I declare Reg[6] as static int Reg[6] (which I do not really want to
do), I get linker errors saying that "myClass::Reg" is undefined in
"myClass.cp" (the source for the class).

It seems odd that I can alter any non-static data members that aren't arrays.

I will certainly appreciate any help,
Jeff Price
Re: C++ - How to alter non-static, private array with a private member function?
#3
Author: Colen Garoutte-Carson
Date: Fri, 03 Nov 1995 14:31
34 lines
1610 bytes
In article <price-0211951815560001@price.mindspring.com>,
price@mindspring.com (Jeffery R. Price) wrote:

> I am using CW7 and am relatively new to C++. I have a class which has a
> private data member declared as:
>    int Reg[6];
> 
> I have a private member function which I want to change the contents of
> Reg[6]. If I do not declare Reg[6] as static, CW7 gives me errors anywhere
> I try to alter Reg[i] in my member function - saying "Illegal use of a
> non-static data member".
> 
> If I declare Reg[6] as static int Reg[6] (which I do not really want to
> do), I get linker errors saying that "myClass::Reg" is undefined in
> "myClass.cp" (the source for the class).
> 
> It seems odd that I can alter any non-static data members that aren't arrays.

Jeff,

     Could you send me a source file that I can use to reproduce this? 
The following works for me:

class x {
   int myArr[20];
   x(void);
};

x::x(void)
{
   myArr[0] = 1;
}

 - Colen Garoutte-Carson, Metrowerks Inc.
Re: C++ - How to alter non-static, private array with a private member function?
#4
Author: MW Ron
Date: Sat, 04 Nov 1995 18:29
33 lines
1816 bytes
 price@mindspring.com (Jeffery R. Price) Writes:

>I am using CW7 and am relatively new to C++. I have a class which has a
>private data member declared as:
>   int Reg[6];
>
>I have a private member function which I want to change the contents of
>Reg[6]. 

Can you show a bit of code, there appears to be a couple mistakes from
your description.
if you have a private member function you would have to call that function
from a public member ( or constructor ) in order to modify your array. 
Did you mean that the member function was public?
You say you want to change the contents of Reg[6];   If this is actually
correct you would have to create a 7 element array,   if you meant you
wanted to change the array Reg, in that case you wouldn't include the
indexes. 

If you could send me a snippet of code I will look at it and see where the
error is at.  I think you are being confused by the error message which
may have taken you off on a wild goose chase.  error messages are
something we are trying to improve all the time.

You might want to download the error message database that works with
QuickView for online help.



Ron

   METROWERKS               Ron Liechty
"Software at Work"    MWRon@metrowerks.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads