TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JASON HENDRIKS
from: CHRIS DOWNS
date: 1997-03-26 08:49:00
subject: Re: compiling dos program

 CR> class A {
 CR>   private:
 CR>      int array[100];
 CR> };
 JH> Is there a way to make the private members static in the class itself,
 JH> even if an objected has automatic (dynamic) duration?
The private member data has the same storage qualification as the public
or protected member data.  It's the _object_ that can be qualified, not
the data members.
 CR> int main(void)
 CR> {
 CR>    A b[50];  // The array b has dynamic duration since it is defined
 CR>              // inside a function body and is not typed static. The
 CR> }            // space for 50 * sizeof(array[]) is reserved on the stack.
 JH> So this object's private members are NOT on the stack:
 There's no 'general rule' as to where they go.  Heck, there's no
 requirement that the computer even _have_ a stack.  But more commonly,
 local variables/objects are on the stack.  So the above would require
 available stack space for 50 objects of type 'A'.
 If you don't have available stack space...
 JH> int main(void)
 JH> {
 JH> static A b[50];
 JH> }
 Then the above would be the way to go.  Now those 50 objects of
 type 'A' won't be on the stack.  
---
 þ Blue Wave/QWK v2.12 þ
---------------
* Origin: St. Louis Users Group (1:100/4)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.