-4

I have a strange C++ class as shown below. I would like to write equivalence of this class in C# but I am in trouble.

class Map
{  
public:

    class Cell
    {
        public:

            class Hash : public unary_function<Cell*, size_t>
            {
                public:

                    static const int C;
                    size_t operator()(Cell* c) const;
            };

            static const unsigned int NUM_NBRS;
            static const double COST_UNWALKABLE;
            double cost;
            Cell(unsigned int x, unsigned int y, double cost = 1.0);
            ~Cell();
            void init(Cell** nbrs);
            Cell** nbrs();
            unsigned int x();
            unsigned int y();

        protected:
            bool _init;
            Cell** _nbrs;
            unsigned int _x;
            unsigned int _y;
    };

    Map(unsigned int rows, unsigned int cols);
    ~Map();
    Cell* operator()(const unsigned int row, const unsigned int col);
    unsigned int cols();
    bool has(unsigned int row, unsigned int col);
    unsigned int rows();

protected:

    Cell*** _cells;
    unsigned int _cols;
    unsigned int _rows;
};  

How it can be converted to C#? Speacially I am confused Hash class which inherits unary_function

Kavindu Dodanduwa
  • 12,193
  • 3
  • 33
  • 46

1 Answers1

0

It does not work that way, you better use the c++ code only as a description of requirements.

If that's not an option, then I can only provide you with the following hint:

// have a create function for you Hash object (I'm trying to simplify here)
public class Hash
{
  static const int C= 1234;
  public static Func<Cell, int> CreateHashObject()
  {
    Func<Cell, int> hashObj= (cl)=>{return cl.GetHashCode() + C;};  // just a dummy implementation to show that you can save a copy of C in the created object.
    return hashObj;
  }
}

// and then wherever you need to create a Hash object
var myHashObject= Hash.CreateHashObject();
AmerS
  • 88
  • 5