Board index » delphi » Posting again "Pointers to classes ?"

Posting again "Pointers to classes ?"

Hi anybody,

     My last post didn't get much response but my question is this :

Q: Can a class be instanciated using a pointer ? What I'd like to do
   create a linked list of linked lists. My structure for the linked
   list is a class TMysinglyLinkList. The operations within this class
   require a pointer to the underlying storage node. I'd like the under-
   lying storage node to be another class which contains another linked
   list. It is this pointer that I am wondering about.

Anybody who can help, please do so. Thanks.

--
  Chris

 

Re:Posting again "Pointers to classes ?"


Hi anybody,

     My last post didn't get much response but my question is this :

Q: Can a class be instanciated using a pointer ? What I'd like to do
   create a linked list of linked lists. My structure for the linked
   list is a class TMysinglyLinkList. The operations within this class
   require a pointer to the underlying storage node. I'd like the under-
   lying storage node to be another class which contains another linked
   list. It is this pointer that I am wondering about.

Anybody who can help, please do so. Thanks.

--
  Chris

Re:Posting again "Pointers to classes ?"


Quote
Chris Haidinyak <chr...@alpha.techspecs.com> wrote:
>Hi anybody,

>     My last post didn't get much response but my question is this :

>Q: Can a class be instanciated using a pointer ? What I'd like to do
>   create a linked list of linked lists. My structure for the linked
>   list is a class TMysinglyLinkList. The operations within this class
>   require a pointer to the underlying storage node. I'd like the under-
>   lying storage node to be another class which contains another linked
>   list. It is this pointer that I am wondering about.

Classes are *always* instantiated using pointers, internally at least.
Don't use a pointer to a storage node, declare a storage node, e.g.

  type
    TMysinglyLinkList = class
      head : TStorageNode;
      ...
    end;

Declare TStoragenode in a similar way.  This doesn't put a copy of the
storage node in the head field, it just stores a pointer there.

Duncan Murdoch

Re:Posting again "Pointers to classes ?"


Quote
Chris Haidinyak <chr...@alpha.techspecs.com> wrote:
>Hi anybody,

>     My last post didn't get much response but my question is this :

>Q: Can a class be instanciated using a pointer ? What I'd like to do
>   create a linked list of linked lists.

        You can make a list of anything. Well, it's a list of pointers, but the
pointers can point to anything. Keep in mind is that objects are already pointers.

        Here's a list consisting of two lists, one of which contains a list:

  var theList:TList;
  begin
    theList:=TList.Create;
    theList.Add(TList.Create);
    theList.Add(TList.Create);
    TList(thelist.List^[0]).Add(TList.Create);
  end;

(The part that took me a minute to get: You need the typecast in the last line
because the compiler doesn't know that theList.List^[0]  is a TList, so that

  thelist.List^[0].Add(TList.Create);

is an "invalid qualifier" error.)

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Other Threads