TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: All
from: Neil Heller
date: 2003-09-07 15:00:00
subject: `new`ing pointers

I'm working on a program that's got 2 classes:  #1 = a node class and #2 
= a linked_list class.  The node class looks like:

class Node {
     private:
          char * SomeString;   // length determined at run-time

     public:
          void SomeFunction();
};


class linked_list {
     private:
          Node * ANode;

     public:
          void build_it();
};


file:  linked_list.cpp

void  linked_list::build_it()
{
     ANode = new Node();

I'm OK so far, so now I compute just how much space I'll need for 
SomeString.  The question I have is - how can I allocate that space?  

ANode->SomeString = new char[CalculatedNumber];

This doesn't work in build_it() because SomeString is a private variable 
in class Node.  In order to allocate the space, do I need to declare 
SomeString as protected?  Would deriving linked_list from Node allow me 
access to private variables in Node from linked_list?

þ CMPQwk 1.42 999

--- Maximus/2 3.01
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)
SEEN-BY: 633/267 270
@PATH: 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

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™.