C++ :: Calling A Function With Dynamically Defined Name
Feb 19, 2013
Is there a way to call a function whose name is defined in a file-stored-list?
In other words: The caller doesn't know in compile time the name of the function.
I'm not talking about polymorphism.
The problem is: I have a list of function names stored in a file, that may change every now and then, and I'd like to call them in the sequence they appear in that list.
I have two projects (Projects A and B). Project A is a dll project, defining a function called "regex".
Project B dynamically loads this DLL, and calls Project A's "regex" function via LoadLibrary/GetProcAddress.
Regex takes a pointer to an std::vector (std::vector<std::cmatch>).
When debugging ProjectB, I can see that, within the code from ProjectA (in the "regex" call), a loop that loops through the elements of the vector outputs all the elements in the vector to console as expected. But the loop in ProjectB ( which executes after ProjectA), which also loops through the vector, and, is supposed to output the elements of the vector, outputs empty strings, not, as I would expect, the same strings (which contain results), as in the loop in Project A.
How is this happening. Does this have anything to do with it being a DLL, and, maybe, somehow values/memory addresses (or something similar) of the vector/its elements being destructed across the Projects/Dlls?
im tasked with creating a linear search script using functions on a 10 element array. the elements are to be supplied by the user as is the search target.
I understand how to create the array and gather that information from the user as well as howto set a variable for "target", this is what im calling it. Those two parts are simple enough.
I am not fully understanding the calling of an array in a function as a pointer. i semi understand the use of a pointer and howto call a normal pointer in a function. i also understand that an array is nothing more then a "special" pointer with a set of consecutive address blocks for the size of the array.
My first user defined function is simple enough
Code: ReadArray(int A[], int size){ int i; printf("Please enter %d integer numbers separated by spaces: ", size); for (i = 0; i < size; i++) scanf("%d", &A[i]); }
Sso nothing out of the ordinary there. that should be a standard for loop and use of scanf, sadly prof has not covered ssanf or any of the other options so i am stuck using scanf for now. maybe someday down the line in a other program or after this course ill get the chance to learn about better options for gathering data from the user.
I am confused as to my next function:
Code: void SearchArray(int A[], int target, int size);
I've not written any code here yet as im not sure if i should call the A[], or *A for the first type of the function?
If i call *A do i then use something like this for my search:
Code: for (*A = 0; *A < size; *A++) if (*A < target) or use A[] insteadA?
Code: for (i = 0; i < size; i++) if (A[i] = target)
I'm making my way through most of this assignment that I have, but now it seems like I've run into a bit of a roadblock. The issue that I'm having is not being able to printf a series of ints that I thought I had previously defined in another function. I don't want to clog up this post with the entire code, so I'll just post one function that defined an int to give an example. I will upload the whole thing upon request however.
Code:
#include <stdio.h> #include <stdlib.h> //Prototypes int AGrade1(int* grade1); int AGrade2(int* grade2); int AGrade3(int* grade3);
[Code] .....
I've tried many many things, but I just cant figure it out. This is what it's supposed to look like.
error C3867: 'WordParsor::Form1::PutUpfrmIO': function call missing argument list; use '&WordParsor::Form1::PutUpfrmIO' to create a pointer to memberc:userskingc++wordparsorwordparsorForm1.h... and the suggestion fix generate another error.
One person suggested the gcroot<> object wrapper... but I do not know how to modify/declair the function or its argument type.
Since the signal function is also in file signal.h and I included it in "my_sygnal.h" file, I'm wondering why the compiler did not say anything about this "double declaration" of the function with the same name.
The function is supposed to return value from the file in my main, but I am getting empty value. I am trying to get better with pointer. Right now just teaching myself.
right now the only way for this code to show value is when in put the putchar(*ps) inside my readfile function. I would like to readfile to return value and print in the main function.
class Base{ public: int getNum(); private: int numToGet; } class Derived: public Base { public: friend ostream& operator<<(ostream& output, const Derived &B);
int myfunc( int a, int b, char * c ) char a = "(int)myfunc()"; char b = "(int,int,char*)" call(a, b, ...) // Function name and return type, params
I want to do function what registers forward what will get callback if the time is right. Basically then i dont need to edit and add extra functions into source files. I just have to include header and use register forward function. If there is anything close to this it would be perfect!
I wrote the following program, it can be compiled and run, but there is warning saying that if virtual function is defined, there should be a destructor. How to do that I tried many different ways I can thought of, but none of them works.
#include <iostream> using namespace std; class cell_c { public: double p; cell_c() {p=1;} virtual void print() {cout<<p<<endl;}
I have been trying to compile this program for 3 days. he subject is my error. I know it has something to do with including the cpp file with the header file however my textbook says this is what I must do in order to use templates. I have tried 2 compilers Code Blocks and Microsoft Visual C++ express 2010.
Here is my code:
header file #pragma once #ifndef _NODE #define _NODE template<class ItemType> class Node {
Write a program using user-defined function which is passed a string and that function should cycle the string.(Do not use any string related functions). E.g.
If the string is : Chetna then it should print as Chetna, hetnaC, etnaCh, tnaChe,naChet, aChetn
The output I'm getting here just counts every letter in the sentence and counts them as vowels. I'm trying to make the user defined function return the amount of vowels within the sentence.
We had to write a "selling program for computers, laptops and tablets", which I did but for the extra credit, we have to have those three points in the application and I have tried but how to do the "extra credit" part, which I really need.
1.) A loop to prompt the user if they would like to place another order
2.) At least one user-defined function
3.) An enumerated data type, array or struct (structure)
I did one of these three, it's a "DO WHILE" loop asking users if they want to make another order, it's right at the beginning of the code.
I am working on a project, where I have to be able to exclude some code fast and dynamicly at compiletime.
I got a scheduler running and actually I just want to remove some of the tasks from it - but at compile time so that the code wont take up space in my microcontroller.
I know that I can use macros like #ifdef #endif etc. But I think that method makes the code unreadable and complicated.
How to archive such functionality a more elegant way?
I need a variable that will just hold a function that I can change in the middle of the application, even to different function type with different amount of parameters ... is this even possible? At the moment I have this
How do I point this one to the variable special, when I want to call it like that (or something similar)
(reply.special)("test string");
is this even possible? if so, how? i tried to create function pointer (didnt compile at all) or use template (neither did this) and how to do this as I discovered functional lib just a while ago.
This a very simple program I created because I dont understand how do this. My goal is to be able to use the pointer *s5 throughout the program. For example I would to like to call other functions and pass that pointer through the function. I understand the dynamic allocation and pointers for the most part but Im confused here because the "new char[20]" variable will die after the function and I dont want it to.
#include <iostream> #include <cstdlib> #include <cstring> using namespace std; void testArray ( char *s5 ); int main ( int argc, char *argv[] )
In a program I'm working on now, i need a milti-dimensional array. To save space, I used dynamically allocated array by using pointers, something like this-
int *arr; arr=new int[col*row];
And now i need to pass this array in a function. What are the parameters in the function declaration statement and at the function call statement?
I have this sample code, that calls a function in a DLL. The function Callback is provided to the DLL as an argument, in order for the DLL to notify my program of relevant changes.
I would like to change this code, so that there is a Main class that opens the connection and there are several separate classes (as below) that register themselves for a specific variable and get notifications if that value is changed. The reason for this is that I want to get several notifications for several independent events and I don't want them to mix. I figured this should look something like this:
Unfortunately this gives me an error: error: cannot convert 'InAClass::Callback' from type 'void (InAClass::)(AmsAddr*, AdsNotificationHeader*, long unsigned int)' to type 'PAdsNotificationFuncEx {aka void (__attribute__((__stdcall__)) *)(AmsAddr*, AdsNotificationHeader*, long unsigned int)}'
At first I thought this was because I don't have the namespace "using namespace std;" on top, but then I should be able to find something that specifically needs to come from the std namespace and is not marked as such. I don't want to rule the option out, but so far I could not find anything like that.
An alternative explanation might be that the Callback function needs to be global, but if I make it global, how can I distinguish between several Callback functions?
I've been trying to get my matrix multiplication program to run a few different ways. My assignments wants me to run it statically using chunks, but we're not supposed to use OpenMPs scheduler. So I'm not sure how that's possible. And secondly, we have to run it dynamically using locks/unlocks.
Every time I try to use the function SaveNewCD, it doesn't write to file correctly. It writes the ~, three characters, then goes into an infinite loop.
#include<iostream> #include<fstream> using namespace std; int SaveNewCD(); int OpenCD(); int main() { char ArtistName[25];