Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to control c++ object externally, at runtime

Posted on 2010-09-18
1
305 Views
Last Modified: 2012-05-10
The title does not say enough. I have a program written in c++ that contains commands available to the user at run time. I'd like to allow the user to execute whatever command they want to by typing in the command. An example will make this clearer.
If I have a program that has a class A

class A
{
public:
    int Add(short a, short b) { return a+b;}
}

And the program creates the object TestA
A* TestA=new A;

I want to know:  is there a way for the user, at run time, to type in

TestA->Add(3,7)   and have it execute the actual object/function?

Obviously, the actual code is a lot more complex than this example, but I hope this makes it clearer.

Thanks, Brian

0
Comment
Question by:BrianDumas
1 Comment
 
LVL 40

Accepted Solution

by:
evilrix earned 500 total points
ID: 33709113
This is perfectly possible but not in a way where you can execute on the fly what they enter. You would have to decide before hand what operations your were prepared to support. You would need to parse whatever is typed into the command line, figure out what command or operation the user wishes to execute and then run it. Writing a parser can be a tricky thing but if you don't mind getting your hands dirty with a DSL (Domain Specific Language) I can highly recommend the Spirit parser that is part of Boost.

http://en.wikipedia.org/wiki/Spirit_Parser_Framework
http://boost-spirit.com/home/
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question