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. C / C++ / MFC
  4. VC++ equivalent of eval

VC++ equivalent of eval

Scheduled Pinned Locked Moved C / C++ / MFC
c++javascripthelptutorial
8 Posts 5 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.
  • K Offline
    K Offline
    Kuldeep Bhatnagar
    wrote on last edited by
    #1

    Hi, In javascript there is an Eval method to do evaluation of string. Can i do something like this in VC++, MFC. Basically i want to create an oblect of the class. The name of the class is dynamic. Example: Eval("new MyClass") // Something like this. Any help would be highly appreciated. Kuldeep

    CPalliniC C N I 4 Replies Last reply
    0
    • K Kuldeep Bhatnagar

      Hi, In javascript there is an Eval method to do evaluation of string. Can i do something like this in VC++, MFC. Basically i want to create an oblect of the class. The name of the class is dynamic. Example: Eval("new MyClass") // Something like this. Any help would be highly appreciated. Kuldeep

      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #2

      Bad times on the horizon. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • K Kuldeep Bhatnagar

        Hi, In javascript there is an Eval method to do evaluation of string. Can i do something like this in VC++, MFC. Basically i want to create an oblect of the class. The name of the class is dynamic. Example: Eval("new MyClass") // Something like this. Any help would be highly appreciated. Kuldeep

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        No you can't do that. C++ is not a scripting language. You could integrate a scripting language (like Python I think) but it may be overkill for what you are trying to do. What do you need to do exactly ? If you can narrow it down, maybe there are some 'simple' solutions for your problem. You'll need to explain your problem a bit more in details.

        Cédric Moonen Software developer
        Charting control [v1.3]

        K 1 Reply Last reply
        0
        • K Kuldeep Bhatnagar

          Hi, In javascript there is an Eval method to do evaluation of string. Can i do something like this in VC++, MFC. Basically i want to create an oblect of the class. The name of the class is dynamic. Example: Eval("new MyClass") // Something like this. Any help would be highly appreciated. Kuldeep

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          Kuldeep Bhatnagar wrote:

          The name of the class is dynamic.

          Compare name of given class and instantiate it!

          Kuldeep Bhatnagar wrote:

          Eval("new MyClass") // Something like this. Any help would be highly appreciated.

          Have a look at RUNTIME_CLASS macro in MFC, though not similar to Eval!

          Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

          1 Reply Last reply
          0
          • C Cedric Moonen

            No you can't do that. C++ is not a scripting language. You could integrate a scripting language (like Python I think) but it may be overkill for what you are trying to do. What do you need to do exactly ? If you can narrow it down, maybe there are some 'simple' solutions for your problem. You'll need to explain your problem a bit more in details.

            Cédric Moonen Software developer
            Charting control [v1.3]

            K Offline
            K Offline
            Kuldeep Bhatnagar
            wrote on last edited by
            #5

            Basically i want to make an object of the class and the name of class will be decided at runtime.

            C 1 Reply Last reply
            0
            • K Kuldeep Bhatnagar

              Basically i want to make an object of the class and the name of class will be decided at runtime.

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #6

              There are several 'ways' to do that. One common things is that all those classes inherits from one common base class (because anyway you need a way to 'store' those items after they have been created). The simplest one is to make a big 'switch' (not a real switch but replace it with if/else clauses because switch only works with integral types not strings). That's an easy solution but not very flexible. Otherwise you can google for the factory design pattern. That's what it does.

              Cédric Moonen Software developer
              Charting control [v1.3]

              K 1 Reply Last reply
              0
              • C Cedric Moonen

                There are several 'ways' to do that. One common things is that all those classes inherits from one common base class (because anyway you need a way to 'store' those items after they have been created). The simplest one is to make a big 'switch' (not a real switch but replace it with if/else clauses because switch only works with integral types not strings). That's an easy solution but not very flexible. Otherwise you can google for the factory design pattern. That's what it does.

                Cédric Moonen Software developer
                Charting control [v1.3]

                K Offline
                K Offline
                Kuldeep Bhatnagar
                wrote on last edited by
                #7

                Switching was always in my mind. Biut i wanted to do without that.

                1 Reply Last reply
                0
                • K Kuldeep Bhatnagar

                  Hi, In javascript there is an Eval method to do evaluation of string. Can i do something like this in VC++, MFC. Basically i want to create an oblect of the class. The name of the class is dynamic. Example: Eval("new MyClass") // Something like this. Any help would be highly appreciated. Kuldeep

                  I Offline
                  I Offline
                  Iain Clarke Warrior Programmer
                  wrote on last edited by
                  #8

                  This article may be of help - I know it was for me. Enumerate your leaf classes[^] You can have classes registering a name, that you can then use to create them. There's functions to get the list of names, so you could add them to a list control if you liked. From his article:

                  IMPLEMENT_LEAF_CLASS(CBlueFilter, CBaseFilter, _T("Blue Filter"))

                  Good luck, Iain.

                  Iain Clarke appears because CPallini still cares.

                  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