This is the class Forum
Code:
class Forum
{
char *name;
int ID , subforumsnum , threadsnum;
Forum **subforums ; //Array of indexes of subforums
Forum *back ;
Thread **threads;
public:
//--------------constructor-destructor etc.
};
This is the class Thread
Code:
class Thread
{
char *name , *creator_name;
int ID,postsnum;
bool locked,sticky;
Forum *back;
Post **posts; //Array of indexes of posts included in thread class
public:
void answer_to_post ( int newID, char *name, int pID );
//------------constructor-destructor etc.
};
And here is the function answer_to_post
Code:
void Thread :: answer_to_post ( int newID, char *cname, int pID )
{
char *newcontent;
Post **temp; //temporary array for posts
cout<<"Type your answer to the post"<<endl;
cin>>newcontent;
temp = new Post *[postsnum+1]; //Expand the array by one more cell from the posts array
for( int i=0 ; i<postsnum ; i++ )
temp[i] = posts[i]; //Copy the posts to temp
delete[] posts; //Delete the old posts array
//Store the new post to the new position of temp array
temp[postsnum] = new Post ( newID, cname, pID, newcontent );
postsnum++; //Increase the number of posts by one
posts = new Post *[postsnum]; //Create new array same size as temp
for( int i=0 ; i<postsnum ; i++ )
posts[i] = temp[i]; //Copy temp array to posts array
delete[] temp; //Delete temp array
}
The basic idea is to make a temporary array (temp) in order store indexes of posts classes, expand the posts array by one cell and store the new post into the last cell.
In reality it is a "dynamic" array which stores post classes.
I do not know why it does not working.
After using it all cells had the same class in every cell.
Thanks