473,386 Members | 1,679 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,386 software developers and data experts.

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(myfunc);
conteggio=0;
};
};

I redefine CLASS and CTOR with these define

#define CLASS(nome_classe) \
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 2100
* 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(myfunc);
conteggio=0;
};
};

I redefine CLASS and CTOR with these define

#define CLASS(nome_classe) \
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(myfunc);
conteggio=0;
};
};

I redefine CLASS and CTOR with these define

#define CLASS(nome_classe) \
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().myfunc();

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(myfunc);
conteggio=0;
};
};

I redefine CLASS and CTOR with these define

#define CLASS(nome_classe) \
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_ref 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
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...
12
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...
10
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...
2
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...
9
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...
2
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...
2
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...

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.