Well, I just started learning c++ and i seem to have some problem. To be specific i have to make a program that recreates the game musical chairs. For this i was supposed to make two classes one named member that would have the position of a player and their id number and also point to the next (last member should point to first.). Second a class named chain that would point at the first member and also have the total number of exsting players. For starters i should create the chain based on a parametre N that would give every member a random id and position them and of course link the powers with each other.
What i wrote was
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
class Member{
public:
int position, number;
Member *next_member;
void Member2( Member *member_, int pos, int id,int N){
if(pos <= N){
member_->position=pos;
member_->number=id;
Member2 (member_->next_member, pos++, rand(), N);
if(pos == N)
member_->next_member = this;
}
}
};
class Chain {
Member *First_member;
int size;
public:
Chain ( int N){
size = N;
srand(time(NULL));
First_member->Member2(First_member, 1 , rand(), N);
}
};
and the main just called chain.
The problem is that when Member2 is called by itself, the whole thing crashes. Any help is good.
Edit: When trying to debug it, it seems there is segmentantion fault when membber_ is used after Member2 has called the Member2 isnide it.