Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Dynamic class pointer arrays?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 WhiteHouse   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 August 1999 - 01:37 PM

Simple question, hard answer... I just need help with how to initialize and use them in my game.

------------------
----------------------
Kim Forsberg
WorldScape Productions
----------------------


Sponsor:

#2 Syntax   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 August 1999 - 07:57 AM

class llave {
public:
char stuff;

private:
int stuff2;
};

llave *ptr;

void main() {

ptr = new llave[number_here];

ptr[x].stuff = 'C';
}

------------------
E-mail with questions, comments, and retorts.


#3 WhiteHouse   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 August 1999 - 10:59 AM

Thanks for the answer but unfortunatley i already know how to do that. What i need to know is how to create an dynamic pointer array that can grow and shrink in size in runtime.

#4 Sixpack   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 August 1999 - 11:19 AM

Whitehouse:

How about using a linked list with whatever data members you need. To use it like an array, overload the [] operator.

Six


#5 WhiteHouse   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 August 1999 - 11:43 AM

Do you perhaps know where I might find a tutorial on the subject of linked lists?

#6 Sixpack   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 August 1999 - 01:29 PM

Try searching for it on yahoo or another search engine. It is a basic concept, so you should be able to find plenty of information.

#7 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 22 August 1999 - 01:37 PM

// linklist.cpp
// linked list
#include

struct link // one element of list
{
int data; // data item
link* next; // pointer to next link
};

class linklist // a list of links
{
private:
link* first; // pointer to first link
public:
linklist() // no-argument constructor
{ first = NULL; } // no first link
void additem(int d); // add data item (one link)
void display(); // display all links
};

void linklist::additem(int d) // add data item
{
link* newlink = new link; // make a new link
newlink->data = d; // give it data
newlink->next = first; // it points to next link
first = newlink; // now first points to this
}

void linklist::display() // display all links
{
link* current = first; // set ptr to first link
while( current != NULL ) // quit on last link
{
cout << endl << current->data; // print data
current = current->next; // move to next link
}
}

void main()
{
linklist li; // make linked list

li.additem(25); // add four items to list
li.additem(36);
li.additem(49);
li.additem(64);

li.display(); // display entire list
}

i got this out of a book dont know if itll help you any





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS