Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to control c++ object externally, at runtime

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

Technology Partners: 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

730 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