this is my Cell.cpp class in c++ :
#include "Cell.h"
Cell::Cell () {
alive = true ;
}
void Cell::setAlive (bool b) {
Cell::alive = b ;
}
bool Cell::isAlive () {
return Cell::alive ;
}
and this is my World.cpp class :
#include "World.h"
#include "Cell.h"
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std ;
World::World (int l , int c ) : lines (l) , columns(c) , rep () {};
World::World (int l , int c , bool ring) : lines (l) , columns(c) , ring (ring) ,rep() {};
World::~World() {};
int World::getLines () {
return lines;
}
int World::getColumns () {
return columns ;
}
void World::genarateWorld () {
srand (time(0));
rep[1][1].Cell::setAlive(true);
}
}
int World::nbAliveNeighbor (int i , int j ) {
int counter=0 ;
return counter ;
}
int World::nbAliveNeighborRing (int i , int j ) {
int counter=0 ;
return counter ;
}
void World::nextGenarate () {
}
void World::print (){
using namespace std ;
for (int i = 0 ; i < 5; i ++){
for (int j = 0 ; j < 5 ; j++) {
if (rep [i][j].Cell::isAlive ())
my [i][j]='*';
else
my [i][j]='-';
}
for (int i = 0 ; i < 5; i ++){
for (int j = 0 ; j < 5 ; j++) {
cout << my[i][j] << "\t" ;
}
cout <<endl ;
}
}
}
and this is my main :
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "Cell.h"
#include "World.h"
using namespace std ;
int main (){
srand (time(0));
World my (5,5);
my.genarateWorld();
// my.print();
return 0 ;
}
in my World.cpp in void World::genarateWorld () rep[1][1].Cell::setAlive(true); have a error i dont know how initialize rep ! please help me
this is Cell.h
#ifndef CELL_H_
#define CELL_H_
class Cell {
private:
bool alive ;
public:
Cell () ;
void setAlive (bool b) ;
bool isAlive () ;
};
#endif
and this is World.h
#ifndef WORLD_H_
#define WORLD_H_
#include "Cell.h"
class World {
private :
bool ring ;
int lines , columns ;
Cell **rep ;
char my [5][5];
public:
World (int l , int c );
World (int l , int c , bool ring);
~World() ;
int getLines () ;
int getColumns () ;
void genarateWorld () ;
int nbAliveNeighbor (int i , int j ) ;
int nbAliveNeighborRing (int i , int j ) ;
void nextGenarate () ;
void print ();
};
#endif /* WORLD_H_ */