Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to control c++ object externally, at runtime

Posted on 2010-09-18
1
Medium Priority
?
311 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

886 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