Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3317012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:32:15+00:00 2026-05-17T22:32:15+00:00

This is a Windows Forms Application project using Visual Studio 2010. That being said:

  • 0

This is a Windows Forms Application project using Visual Studio 2010. That being said:

I’ve an unmanaged ‘Vector’ implementation, something like:

template<class T>
class Vector {
public:
    T* data;
    unsigned len;

    (...constructors and operators overloading like =, [], == and !=)
};

It works great. I’ve done several tests before with it. After that I’ve implemented an also unmanaged ‘Matrix’ that uses the previously class Vector. Something like:

template<class T>
class Matrix : public Vector<Vector<T>*> {

public:
    Matrix(unsigned height = 20, unsigned width = 20) 
    : Vector(height) 
    {
    for (unsigned i = 0; i < height; i++) {
            data[i] = new Vector<T>(width);
        }
    }

    Vector<T> operator[](unsigned pos) {
        return data[pos];
    }
};

It also works great but with unmanaged data as T. My main objective, access data using [][], worked as expected.

But now I want to use this Matrix class inside managed code, with data T also being managed code, in this case a ‘Cell’ already implemented:

public ref class Cell {
public:
    bool dead;

public:
    Cell() {
        this->dead = false;
    }
    Cell(bool dead) {
        this->dead = dead;
    }

    virtual String^ ToString() override {
        return (this->dead ? "0" : "1");
    }
};

I’m doing the initialization this way:

Matrix<gcroot<Cell^>>* cells = new Matrix<gcroot<Cell^>>(height, width);

for (unsigned i = 0; i < height; i++) {
    for (unsigned j = 0; j < width; j++) {
        gcroot<Cell^> * cell = new gcroot<Cell^>;
        cells[i][j] = cell; // ERROR!!
    }
}

The line where I assign the cell to matrix always returns the error in the title. Other operators (aside from ‘=’) also gives me the same error.

I’ve tried everything but I can’t find a way to fix this. I’m really avoiding to touch Vector and Matrix classes because they’ve to be unmanaged and I’ve to use gcroot to inject managed data inside it.

At the end of the day, Cell will be a System::Windows::Forms::Button so the implementation has to be this way.

Any ideas? Sorry if I was unable to explain myself. If you need more code from Vector class please tell. Thanks is advanced 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:32:16+00:00Added an answer on May 17, 2026 at 10:32 pm

    Honestly, you are going to have to do a lot of work to use this native C++ code direct from managed code (if it’s even possible).

    It’s probably going to be easier to reimplement it in STL/CLR, if you need to stick with C++, or in C# if not. The mere existence of this STL/CLR class library should tell you something about how advisable it is to use native C++ STL containers in this way.

    EDIT:
    You can probably fix the compilation error by using

    template<class T> class Matrix : public Vector<Vector<T>>
    

    Your operator[] should not return by value, or the underlying Vector element will not be altered as you will be working with a copy of what’s in the Matrix.

    Vector<T>& operator[](unsigned pos) {
    

    Comments about this being non-trivial stand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a Windows Forms application using Visual Studio 2008 C# that uses an
Background In Visual Studio 2008 Create a new Windows Forms Application, this will create
I have a Visual Studio 2010 Windows Forms application in which I start a
When you open a new C# Windows Forms Application project in Visual Studio 2008,
This is a Windows Forms application. I have a function which captures some mouse
This code works in a windows forms application (it shows the preview) but not
I'm having an issue with a Visual Studio 2008 web application project where changes
What tools are useful for automating clicking through a windows form application? Is this
Take the method System.Windows.Forms.Control.Invoke(Delegate method) Why does this give a compile time error: string
This is a strange one... In a windows forms app (VB.NET/VS 2005) I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.