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

  • Home
  • SEARCH
  • 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 8640473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:17:18+00:00 2026-06-12T11:17:18+00:00

I ve got a problem with allocating cli::array in function. I have this kind

  • 0

I ve got a problem with allocating cli::array in function.

I have this kind of object:

array<double>^ tmsr2;

now I want to allocate it in function so:

void allocate(array<double>^ tmsr2)
{
    tmsr2=gcnew array<double>(100);
}

Now, tmsr2 in function gets allocated well but I lose the pointer when returning to main()
The problem is clear to me, just like if I want to allocate simple array “double *a”; I need to pass pointer to function so “&a” and then everything works fine. I just don’t know the syntax with managed arrays. Help much appreciated.

Peter

  • 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-06-12T11:17:20+00:00Added an answer on June 12, 2026 at 11:17 am

    Since array<double> is a managed type, you can use a managed tracking reference here, instead of a plain reference.

    void allocate(array<double>^% tmsr2)
    {
        tmsr2 = gcnew array<double>(100);
    }
    

    Here’s my test app:

    public ref class AsAClassField
    {
    public:
        array<double>^ b;
    
        AsAClassField()
        {
            allocate(b);
            Debug::WriteLine("b = " + (b != nullptr ? "array" : "null"));
        }
    };
    
    int main(array<System::String ^> ^args)
    {
        array<double>^ a = nullptr;
        allocate(a);
        Debug::WriteLine("a = " + (a != nullptr ? "array" : "null"));
        AsAClassField^ foo = gcnew AsAClassField();
    
        return 0;
    }
    

    Output:

    a = array
    b = array
    

    Of course, you could always switch your allocate function to return the newly allocated array, rather than taking it as a reference. That would be more in the managed style.

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

Sidebar

Related Questions

Previously, I have worked on local notifications, but I got problem in it now.
I have got problem with this method: public List<int> menu_wid_w_kat() { DataSet1TableAdapters.menu_widac_wszystkoTableAdapter pk =
I got problem for sorting array of nsdate. so i have array of date
I've got problem with DirectX in C#. I want to draw some lines. Firstly
I've got problem for my application. I want to start connectbot from my application
have a nice day. I got problem when trying to create an image from
I want to ask about strcpy. I got problem here. Here is my code:
got a problem, can't get my head around this jquery and would appreciate your
I have got problem with creation Mutex. I don't know why because server is
I got a similar problem to this guy while processing 4MB log file. Actually

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.