By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

an empty class?

P: 84
I have a program that I'm trying to understand with the following code in a header file:
Expand|Select|Wrap|Line Numbers
  1. class  Mathobject {};
  2.  
  3. typedef void (Mathobject::*moDerivs) (const double, const double*, double*) const;  //! common derivs for Nrecipes ODE
  4. typedef double (Mathobject::*moSingle) (const double) const; //! Simple f(x)   
  5.  
  6.  
Hence it is adefinition of the class mathobject without any member function or objects declared. My interpretation is that one can add any function to this class (via the ::) as being a member function... is this right? Because it seems to be done just afterwards.
Mar 22 '07 #1
Share this Question
Share on Google+
3 Replies


Ganon11
Expert 2.5K+
P: 3,652
Although I can't say it with any authority, that would appear to be correct...that is, I think your interpretation is correct, but I can't be sure.
Mar 22 '07 #2

P: 84
It is also motivated by the fact that the guy who wrote the program explains beforehand the reason of existence of this class as being (shortened by me):
Reason of existence: if an object (=belonging to a given class) calls a function f1 which is not of the given class and that function f1 needs another function f2 of the given class as well as data from the object, then the object and the function f1 need to belong to the same class. Hence mathobject defines a kind of mother class of all classes.

Thanks anyway, if we are already in two thinking it is right the probability being it tends more and more to one.
Mar 22 '07 #3

Banfa
Expert Mod 5K+
P: 8,916
What you have is an empty class (that I suspect is being used as a base class for other classes) and type derfinitions of pointers to member functions.

Pointers to members (including member functions) are one of the more esoteric and less used features of C++.

Google Member Function Pointers

I liked this tutorial


Basically a member function pointer allows you to record a pointer to a particular function in a class and then use it on different objects of that class.

In this case it seems to be being used to enable visibility of functions and data between classes although I think there are other ways of doing that.
Mar 22 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.