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
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Quick Question about Static variables inside function calls in MC++ [modified]

Quick Question about Static variables inside function calls in MC++ [modified]

Scheduled Pinned Locked Moved Managed C++/CLI
csharpquestionc++dotnetalgorithms
4 Posts 2 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.
  • R Offline
    R Offline
    Richard Green
    wrote on last edited by
    #1

    First off - a bit of background: For a project i'm working on I need to distribute objects to groups of users based on a number of different algorithms, my idea was to store the state for each algorithm inside their respective functions using static variables. This was to be done in C# until I realised C# doesn't support this functionality but i know C++ does. Sooo ... Does Managed C++ support static variables inside functions in the same way as standard C++ does or is it a limitation of the CLR that means this functionality isn't available in .NET? Thanks Richard

    Richard Green

    modified on Thursday, January 24, 2008 7:43:20 AM

    R 1 Reply Last reply
    0
    • R Richard Green

      First off - a bit of background: For a project i'm working on I need to distribute objects to groups of users based on a number of different algorithms, my idea was to store the state for each algorithm inside their respective functions using static variables. This was to be done in C# until I realised C# doesn't support this functionality but i know C++ does. Sooo ... Does Managed C++ support static variables inside functions in the same way as standard C++ does or is it a limitation of the CLR that means this functionality isn't available in .NET? Thanks Richard

      Richard Green

      modified on Thursday, January 24, 2008 7:43:20 AM

      R Offline
      R Offline
      Richard Green
      wrote on last edited by
      #2

      Never mind, I refactored my code so each algorithm is inside its own class and can now use static class members to store current state. Richard

      Richard Green

      L 1 Reply Last reply
      0
      • R Richard Green

        Never mind, I refactored my code so each algorithm is inside its own class and can now use static class members to store current state. Richard

        Richard Green

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

        That is the right way to do it, whatever language you choose. State belongs to an object, not to a function. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


        R 1 Reply Last reply
        0
        • L Luc Pattyn

          That is the right way to do it, whatever language you choose. State belongs to an object, not to a function. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


          R Offline
          R Offline
          Richard Green
          wrote on last edited by
          #4

          Yeah, it was just one of those mornings eariler - took a 5min break came back and realised I was going about it backwards :)

          Richard Green

          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