Solved

How to control c++ object externally, at runtime

Posted on 2010-09-18
1
308 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
[X]
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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

623 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