1

I am attempting to create a grid of hexagons on a windows form.

To do this i have created a 'hexagon' class with the header file as follows:

ref class Hexagon
{
public:
    Hexagon(int X, int Y, int I, int J);
    Hexagon();
private:
    array<Point>^ vertices;
    Point Centre;
    int i, j;
public:
    int GetX();
    int GetY();
    void SetCentre(int X, int Y);
    void CalculateVertices();
    array<Point>^ GetVertices();
    void drawHexagon();
};

i then want to have a 2 dimensional array storing these hexagons. my attempt at doing this is as follows:

array<Hexagon^,2>^ Grid

but i get the 'a variable with static storage duration cannot have a handle or tracking reference type'

how do i create a 2d array to add hexagons to?

6
  • This isn't C++ code. You need a different language tag. Commented Mar 2, 2014 at 15:51
  • is it not?! im doing it in a c++ file using a c++ compiler in visual studio 2012, im just using .NET DLL? Commented Mar 2, 2014 at 15:55
  • Definitely not. It is probably some kind of hybrid language supporting some part of C++ syntax. But this code is not valid C++. Commented Mar 2, 2014 at 16:02
  • 1
    just done a quick bit of research - the language is not called C++, it's called C++/CLI. One reason why it's called thus might be that plain C++ is a complete subset of C++/CLI (i.e. any conformant C++ program is also a conformant C++/CLI program). Commented Mar 2, 2014 at 16:18
  • @JabbaWook I would advise you to rely on "regular" c++ if you dont have any good reason to use this extension. Commented Mar 2, 2014 at 16:23

1 Answer 1

4

A ref class declares a class which is managed by the garbage collector. One strong restriction that the C++/CLI compiler applies to such declarations is that such class cannot contain non-managed objects. That very often turns out poorly when the object is moved when the heap is compacted, invalidating unmanaged pointers to such non-managed objects.

The likely trouble-maker is the Point type, there are no other candidates. A sample declaration for a managed Point type that doesn't have this problem is:

   public value struct Point {
       int x, y;
   };

Or use the baked-in System::Drawing::Point type instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.