-4

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_ */
mohsen
  • 1
  • 3
  • You are missing some `class` declarations...and specify the *exact* error. – crashmstr Nov 25 '13 at 17:02
  • You've posted plenty of irrelevant code, but not the declaration of `rep`, the definition of `Cell`, or the error message. It's difficult to guess what's going wrong without that information. – Mike Seymour Nov 25 '13 at 17:13
  • my problem is , how to initialize rep [i][j] , that initialize setAlive(bool b) – mohsen Nov 25 '13 at 17:16

1 Answers1

1

You're adding the Cell:: in all sorts of places where it's not needed, and in one place where it's an error

rep[1][1].setAlive(true);

not

rep[1][1].Cell::setAlive(true);

and

bool Cell::isAlive () {
    return alive ;
}

not

bool Cell::isAlive () {
    return Cell::alive ;
}

and

void Cell::setAlive (bool b) {
    alive = b ;
}

not

void Cell::setAlive (bool b) {
    Cell::alive = b ;
}
john
  • 85,011
  • 4
  • 57
  • 81
  • ok but this is not my main problem may main problem is rep !! – mohsen Nov 25 '13 at 17:25
  • @mohsen You need to describe your main problem at bit better. I talked about rep in the answer above. Use `rep[1][1].setAlive(true);`. Was your main problem something else? – john Nov 25 '13 at 17:28