473,761 Members | 10,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HOW TO??? call an unknown function's method

Hello, I have to call a member funtion "myclass.myfunc ()" from another
function "void method();" but I don't know the name of "myclass" and
"myfunc()" because I'm writing a library.h that has to be put in the
header of a given file.

this is an example of the given file, obviously I can't modify this
file, but I know that the funcitions are always without arguments and
void type.

CLASS(myclass){
int counter;

void myfunc();

CTOR(conta){
TYPE_METHOD(myf unc);
conteggio=0;
};
};

I redefine CLASS and CTOR with these define

#define CLASS(nome_clas se) \
struct nome_classe
#define CTOR(nome_func) \
nome_func()

and I can redefine TYPE_METHOD using #define with whatever I want, but
there must be the call to "method(... .);

void method(.....){
while(1){
myclass.myfunc( );
WAIT();
}
}

the function method can take everthing you want.

Thanks for any help!

Paolo

Mar 17 '06 #1
3 2116
* pa******@gmail. com:
Hello, I have to call a member funtion "myclass.myfunc ()" from another
function "void method();" but I don't know the name of "myclass" and
"myfunc()" because I'm writing a library.h that has to be put in the
header of a given file.

this is an example of the given file, obviously I can't modify this
file, but I know that the funcitions are always without arguments and
void type.

CLASS(myclass){
int counter;

void myfunc();

CTOR(conta){
TYPE_METHOD(myf unc);
conteggio=0;
};
};

I redefine CLASS and CTOR with these define

#define CLASS(nome_clas se) \
struct nome_classe
#define CTOR(nome_func) \
nome_func()


The above shouldn't compile then (also macros are generally Not A Good
Idea, I think you'll find the FAQ referring to them as Evil).

Post something complete that compiles except for your problematic call.

Mark that call with a comment, and try to describe where you get the
information about what to call.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 17 '06 #2
pa******@gmail. com wrote:
Hello, I have to call a member funtion "myclass.myfunc ()" from another
function "void method();" but I don't know the name of "myclass" and
"myfunc()" because I'm writing a library.h that has to be put in the
header of a given file.

this is an example of the given file, obviously I can't modify this
file, but I know that the funcitions are always without arguments and
void type.

CLASS(myclass){
What's that? A macro? What does it expand into? Ah, I see... A mere

struct myclass {

So, why do you think you need that crap? Just write "struct myclass".
int counter;

void myfunc();

CTOR(conta){
Huh? This should not compile. Your 'CTOR' will expand into

conta(){

which is definitely not the same as the name of the class ("myclass") you
just gave it above...
TYPE_METHOD(myf unc);
conteggio=0;
};
};

I redefine CLASS and CTOR with these define

#define CLASS(nome_clas se) \
struct nome_classe
#define CTOR(nome_func) \
nome_func()

and I can redefine TYPE_METHOD using #define with whatever I want, but
there must be the call to "method(... .);

void method(.....){
while(1){
myclass.myfunc( );
What's "myclass"? Is that the same as the name of the struct you just
defined? Then you cannot use the "dot" notation. You either need
a temporary of the type 'myclass' or you need the scope resolution:

myclass().myfun c();

or

myclass::myfunc ();

depending on what you really need it for.
WAIT();
}
}

the function method can take everthing you want.


It all sounds (and looks) like a REALLY BAD IDEA(tm). Why do you think
you need all that macro nonsense? What is your ultimate goal here? It
does seem that templates are a better choice.

V
--
Please remove capital As from my address when replying by mail
Mar 17 '06 #3
pa******@gmail. com wrote:
Hello, I have to call a member funtion "myclass.myfunc ()" from another
function "void method();" but I don't know the name of "myclass" and
"myfunc()" because I'm writing a library.h that has to be put in the
header of a given file.

this is an example of the given file, obviously I can't modify this
file, but I know that the funcitions are always without arguments and
void type.

CLASS(myclass){
int counter;

void myfunc();

CTOR(conta){
TYPE_METHOD(myf unc);
conteggio=0;
};
};

I redefine CLASS and CTOR with these define

#define CLASS(nome_clas se) \
struct nome_classe
#define CTOR(nome_func) \
nome_func()

and I can redefine TYPE_METHOD using #define with whatever I want, but
there must be the call to "method(... .);

void method(.....){
while(1){
myclass.myfunc( );
WAIT();
}
}

the function method can take everthing you want.

Thanks for any help!

Paolo


As Alf and Victor noted, it's unclear exactly what you're trying to do.
Depending on your design, you might be able to accomplish what you want
with standard inheritance and virtual functions (probably the preferred
method):

struct A
{
virtual void myfunc() { ... }
};

struct B : A
{
virtual void myfunc() { ... }
};

struct C
{
void foo( A& a ) { a.myfunc(); }
}

Or, you might need to use some combination of templates and functors.
If myfunc is always the name of the function, you could create a class
that calls it on an arbitrary type like this:

struct C
{
template <class T>
void foo( T& t )
{
// ...
t.myfunc();
}
};

Or you could use the standard library's (or Boost's or your own)
functionals to create a functor object:

struct C
{
template <class Fn>
void foo( Fn fn )
{
// ...
fn();
}
};

where the functor fn invokes your function on your particular object
with any necessary parameters, akin to std::mem_fun_re f and
std::bind1st.

Cheers! --M

Mar 17 '06 #4

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

Similar topics

53
5741
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
12
1631
by: ectoplasm | last post by:
Abstract base class A. Derived from A are class B and C, both concrete. I hold a pointer to an object of class A, an instance which is either B or C. I have trouble with making the following work, while I think it should be possible: A *pA = new B; // One of... A *pA = new C; // ...these two
10
2878
by: ndm | last post by:
Hi, Just wondering if any one knows a way to pass and enumerate an unknown number of parameter to a VB function. I want to create a Min/Max functions that can: a) take an variable number of parameters b) determine how many parameter are passed to it c) loop through parameters PS. I can't use an array or collection
2
1422
by: manny | last post by:
Hi all c++ experts I have a problem with determining why are certain functions called in the given code example. In main, fkcja1(one) is called, then in its body it should call fkcja1(1) but actually B::B(int a) is called (WHY?) and before returning from fkcja1(one) there is a call to (WHY?) Why there is no call to void fkcja1(int c) !
9
10738
by: Klaus Johannes Rusch | last post by:
IE7 returns "unknown" instead of "undefined" when querying the type of an unknown property of an object, for example document.write(typeof window.missingproperty); Has "unknown" been defined as a valid return value for the typeof operator in a later version of ECMAScript or is this a JScript "feature"? -- Klaus Johannes Rusch
2
1538
by: johnmay1248 | last post by:
I am having a problem with queries running in this code When I use the query "SELECT * FROM sample" the code runs and the data grid binds and shows the contents of the sample table. If I change the query to filter the results such as "SELECT * FROM sample WHERE (sales 2000)" the code fails on - objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) with an unknown error. If I load the database up into access2000...
2
1510
by: Gillard | last post by:
hello I get a dll with standard call in C ++ but I really do not know how to use it in VB anyone can help??? there is the declarations in cpp to use the functions #ifndef SFPDF_H #define SFPDF_H
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.