473,377 Members | 1,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,377 software developers and data experts.

invoking a method on an object

I am trying to solve a problem in our application. I am at a point
where I want to invoke a method on the object based on the name of the
method.

================================================== ====
For Example :

From a configuration file I would know that I have to invoke a method
"foo" on object "o".

So, I have 2 strings "foo" and "o" in the code at run time.

I have to now do something to invoke this method "foo" on "o". That is
I have to do o.foo() at runtime.

================================================== ====

I know this is possible in java using reflection. Does any one know
how I can do this in C++?

Thanks in advance for any help.

-Ganesh.
Jul 22 '05 #1
1 1542

"Ganesh Chakka" <cb******@hotmail.com> wrote in message
news:35**************************@posting.google.c om...
I am trying to solve a problem in our application. I am at a point
where I want to invoke a method on the object based on the name of the
method.

================================================== ====
For Example :

From a configuration file I would know that I have to invoke a method
"foo" on object "o".

So, I have 2 strings "foo" and "o" in the code at run time.

I have to now do something to invoke this method "foo" on "o". That is
I have to do o.foo() at runtime.

================================================== ====

I know this is possible in java using reflection. Does any one know
how I can do this in C++?


One possible way is -
1. Create objects using the factory pattern.
2. Maintain a map of string and pointer to member function.
typedef void (A::*foofn)();
map<string, foofn> a;
3. Invoke methods using the lookup in map.

Ofcourse this method has limitations.

-Sharad
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JCE | last post by:
I need to programmatically invoke an asp:Button click event from a javascript function. The page containing the script and the button is the HTML page associated with a WebUserControl-derived...
2
by: Jeff | last post by:
I am trying to dynamically load an assembly via reflection and then invoke a method of that assembly that will populate a custom type collection passed into the method byref. I am able to...
25
by: MuZZy | last post by:
Hi, I'm currently rewriting some functionality which was using multithredaing for retrieving datasets from database and updating a grid control. I found that the grids (Infragistics UltraGrid,...
12
by: Hemanth | last post by:
Hi, I have a base class with a static constructor and some abstract methods. Derived classes implement these methods. From articles on the web, it appears that there is no guarentee that this...
4
by: Praveen Chandra | last post by:
Hi, I just wanted to put down the issue with more detailed information so that you can help us get to the right Microsoft resource for a solution! Here is the problem description... Our...
0
by: swatitalati | last post by:
Hello when i invoke a method of web service i m getting error like Server was unable to process request. --> Requested registry access is not allowed. syntex for invoking method is as below ...
1
by: Suds | last post by:
Hi, I'm having an issue with invoking a Generic method that takes Generic Arguments. My method signature is public void GenericMethodWithGenericArguments<E, V>(List<EtheFirstList,...
3
by: Rotsey | last post by:
Hi, I am getting a Exception has been thrown by the target of an invocation error when invoking a method Here is the crux of the code. I realise it could be a few things, any one give me...
2
by: =?Utf-8?B?SmltIE93ZW4=?= | last post by:
Hi John, Hopefully this post will find its way back to you - or perhaps be answered by someone else. As I mentioned in my last post on the earlier portion of this thread, changing the...
0
by: everlast88az | last post by:
I have created an active x web browser axWebBrowser1. I navigate to the url through: axWebBrowser1.Navigate(URL, ref Zero, ref EmptyString, ref EmptyString, ref EmptyString); ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.