?
Solved

Enum Functions

Posted on 2002-06-06
6
Medium Priority
?
310 Views
Last Modified: 2010-04-02
hi All,
i have a C++ generic class (not MFC)
i have a bunch of functions, and would like to know
how can i Enumerate those function
so the caller won't need to call each one of the explicitly.

thanks
Shay
0
Comment
Question by:Shay050799
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 7060208
What do you mean!

There is no built-in way to find out all the functions in a class--nor would you really want to call them all either.  (amoung the functions inside a class are destructors, and constructors, and you would not want to call them at "random" times)

You can provide a single function in the class that calls the other functions that you want to have called, like

Class A
{
pyblic:
    void F1();
    void F2();
    void F3();
    void F4();

    void CallAll()
    {
       F1();
       F2();
       F3();
       F4();
    }
};


But you won't find any automated way of doing this.   Like what would you do if some functions required parameters?  ie. what about

class A
{
public:
    void  F1(int i);
    void F2(double d, int i);
};

How could you call both of those functions from one "general" mechanism?


Maybe it would be best if you explained your cicumstances and what you need to accomplish, then we can try to suggest a better means fo getting there.  I think your current approach is a deadend.
0
 
LVL 30

Expert Comment

by:Axter
ID: 7060296
I'm not sure if this is the kind of thing your looking for.
The following method allows you to store an array of member functions, and them by iterating through the array.
You can also use a vector to store the member functions.

#include <stdlib.h>

class foo
{
public:
     int g1(){return 1;}
     int g2(){return 2;}
     int g3(){return 3;}
     int g4(){return 4;}
     int g5(){return 5;}
     int g6(){return 6;}
};

int main(int argc, char* argv[])
{
     typedef int (foo::*FuncPtr)();
     FuncPtr ListOfFunctions[6] = {foo::g1, foo::g2, foo::g3, foo::g4, foo::g5, foo::g6};

     for (int i = 0;i < 6;++i)
     {
          foo MyFoo;

          printf("%i = %i\n", i, (MyFoo.*ListOfFunctions[i])());
     }
     
     system("pause");
     return 0;
}

0
 
LVL 30

Expert Comment

by:Axter
ID: 7060299
FYI:
With above method all the types need to have the same return type and accept the same argument type(s).
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 22

Expert Comment

by:nietod
ID: 7060319
>> With above method all the types need to have the same return type
>> and accept the same argument type(s).
in other words, the functions all need to have the same "signature"  which includes calling convention as well.

It would really help if we knew what this is for.
0
 
LVL 11

Expert Comment

by:griessh
ID: 7261534
Dear Shay

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to split between

     "Axter & nietod"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7332900
Force accepted

** Mindphaser - Community Support Moderator **

Axter, there will be a separate question with points for your help.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question