Click here to Skip to main content
11,502,821 members (35,758 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ function argument
I am wondering if how I can write a function to detect the parameter type, value and function name and return value of another function.

For example. I have a function:

double average(string datapath, double *data, int numofinput)
{
   // some code here
}

I want to have another function, such as detector(), which can be inserted into the function to be detected, like

double average(string datapath, double *data, int numofinput)
{   
   // some code here
   detector();
}
and the detector will return:

name: average
returned value: 2.43
pathname: string='C:/Users/Nick/Data/'
data: pointer=0x0065
numofinput: int=17

Somthing like that. Any suggestion is highly appreciated. Thanks. Nick
Posted 3-Oct-12 4:20am
Edited 3-Oct-12 4:47am
v3
Comments
Richard MacCutchan at 3-Oct-12 10:59am
   
You can do this in .NET with reflection but not in pure C++ as far as I know.
Legor at 4-Oct-12 3:50am
   
Maybe it can be done with generic programming. But in general C++ doesn't provide reflection.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try creating a (class) string variable str,
and everytime a function is called, it updates the data in str (either overwrite it or just add), at the end, cout the value of str.

(i think you are just using it to perform debuging...)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100