Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. how to declare array of object [modified]

how to declare array of object [modified]

Scheduled Pinned Locked Moved Managed C++/CLI
questionc++data-structurestutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    m_mun
    wrote on last edited by
    #1

    Hi, Suppose I have a class named "Bounce". How can i declare array of objects in another class using managed c++? Thanks to all

    modified on Wednesday, January 6, 2010 7:09 AM

    L D 2 Replies Last reply
    0
    • M m_mun

      Hi, Suppose I have a class named "Bounce". How can i declare array of objects in another class using managed c++? Thanks to all

      modified on Wednesday, January 6, 2010 7:09 AM

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Did you try anything at all? What is your book telling you? I would try something similar to:

      array < String ^ > ^ tab=gcnew array < String ^ > (200);

      :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      Happy New Year to all.
      We hope 2010 soon brings us automatic PRE tags!
      Until then, please insert them manually.


      1 Reply Last reply
      0
      • M m_mun

        Hi, Suppose I have a class named "Bounce". How can i declare array of objects in another class using managed c++? Thanks to all

        modified on Wednesday, January 6, 2010 7:09 AM

        D Offline
        D Offline
        Dave Doknjas
        wrote on last edited by
        #3

        It's far more common these days to use a generic list, such as System::Collections::Generic::List. List ^ myList = gcnew List(); Removing and inserting is easier this way.

        David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com

        S 1 Reply Last reply
        0
        • D Dave Doknjas

          It's far more common these days to use a generic list, such as System::Collections::Generic::List. List ^ myList = gcnew List(); Removing and inserting is easier this way.

          David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com

          S Offline
          S Offline
          SteelModule
          wrote on last edited by
          #4

          Hello, I have another problem: I would like to use ArrayList for collecting of unknown number of System::Drawing::Point structures. But I´m not able to use it in some GDI+ drawing functions feg. Graphics::DrawCurve(...). It forces me to use cli::array, it is totally ugly, I ended up with something like this:

          // Dynamic array
          ArrayList^ arr = gcnew ArrayList;
          // Add some test data
          arr->Add(Point(0, 0));
          arr->Add(Point(25, 25));
          arr->Add(Point(50, 75));
          arr->Add(Point(75, 100));
          .
          .
          arr->Add(Point(225, 325));

          // Somewhere prior drawing...
          array^ pt = gcnew array(arr->Count);
          for(int i = 0; i < arr->Count; i++)
          pt[i] = (Point)arr[i];

          // Actual drawing...
          g->DrawCurve(pen, pt);

          It works, but... Is there a better way to do something like this? I'm sure I'm wrong, but I learn C++/CLI about an hour :-). There are no such problems if I use GDI+ in Win32 API, MFC...

          D 1 Reply Last reply
          0
          • S SteelModule

            Hello, I have another problem: I would like to use ArrayList for collecting of unknown number of System::Drawing::Point structures. But I´m not able to use it in some GDI+ drawing functions feg. Graphics::DrawCurve(...). It forces me to use cli::array, it is totally ugly, I ended up with something like this:

            // Dynamic array
            ArrayList^ arr = gcnew ArrayList;
            // Add some test data
            arr->Add(Point(0, 0));
            arr->Add(Point(25, 25));
            arr->Add(Point(50, 75));
            arr->Add(Point(75, 100));
            .
            .
            arr->Add(Point(225, 325));

            // Somewhere prior drawing...
            array^ pt = gcnew array(arr->Count);
            for(int i = 0; i < arr->Count; i++)
            pt[i] = (Point)arr[i];

            // Actual drawing...
            g->DrawCurve(pen, pt);

            It works, but... Is there a better way to do something like this? I'm sure I'm wrong, but I learn C++/CLI about an hour :-). There are no such problems if I use GDI+ in Win32 API, MFC...

            D Offline
            D Offline
            Dave Doknjas
            wrote on last edited by
            #5

            Use a list and it's 'ToArray' method: List^ arr = gcnew List(); g->DrawCurve(pen, arr.ToArray());

            David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com

            S 1 Reply Last reply
            0
            • D Dave Doknjas

              Use a list and it's 'ToArray' method: List^ arr = gcnew List(); g->DrawCurve(pen, arr.ToArray());

              David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com

              S Offline
              S Offline
              SteelModule
              wrote on last edited by
              #6

              Thank you for a fast reply, it helped. :) Actually I have found ToArray() function previously, I used it (but with ArrayList) in trials with both C# and C++/CLI, but it doesn't compile in C++/CLI, I got error C2664. In C# I was able to cast it, it does compile and work, not so in C++. Btw., it still copies one array into another as I did, it looks much more clean, but again not very efficient... X| I used to write same app in C# and C++/CLI for learning, to see, which .NET code will look better for me. I use native C/C++/ASM long time professionaly, I work as a lead programmer on a big, well known engineering computational SW package, written mainly in native C++. It has an extensive GUI (our boss is GUI guy :suss:), which we would like to port to some C family .NET language, maybe with WPF.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups