T
Thomas Matthews
Hi,
I have a hierarchy of classes and would like to create an array
of pointers to member functions that could also contain pointers
to the parent member functions as well.
What is the syntax for this?
#include <string>
using std::string;
class Base
{
string title;
protected:
string to_str_title(void) const;
};
class Published
: public Base
{
string publisher;
protected:
string to_str_publisher(void) const;
};
class Book
: public Published
{
string author;
string isbn;
protected:
string to_str_author(void) const;
string to_str_isbn(void) const;
};
In the above example, all the member functions have the signature:
string {function_name}(void) const;
I am creating a function that will return a field's data as a string
based on an index. I intend to have a vector of member functions
so that I can have each parent push their member function into the
vector. This eliminates the need for fixed magick numbers for the
field indices and not have to worry about the indices of parent
classes. (I am supply an interface to treat the classes as
records of fields.)
Questions:
0. The C++ FAQ section 30 does not discuss inheritance and
member functions. "The C++ Programming Language, Special
Edition", does not discuss inheritance of member functions
either.
1. What is the syntax for declaring a typedef to a member function
that allows for parent functions?
2. Where does the "const" go in the typedef for constant member
functions?
3. Can the member functions be private even though they are
accessed in a vector created by the leaf class?
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
I have a hierarchy of classes and would like to create an array
of pointers to member functions that could also contain pointers
to the parent member functions as well.
What is the syntax for this?
#include <string>
using std::string;
class Base
{
string title;
protected:
string to_str_title(void) const;
};
class Published
: public Base
{
string publisher;
protected:
string to_str_publisher(void) const;
};
class Book
: public Published
{
string author;
string isbn;
protected:
string to_str_author(void) const;
string to_str_isbn(void) const;
};
In the above example, all the member functions have the signature:
string {function_name}(void) const;
I am creating a function that will return a field's data as a string
based on an index. I intend to have a vector of member functions
so that I can have each parent push their member function into the
vector. This eliminates the need for fixed magick numbers for the
field indices and not have to worry about the indices of parent
classes. (I am supply an interface to treat the classes as
records of fields.)
Questions:
0. The C++ FAQ section 30 does not discuss inheritance and
member functions. "The C++ Programming Language, Special
Edition", does not discuss inheritance of member functions
either.
1. What is the syntax for declaring a typedef to a member function
that allows for parent functions?
2. Where does the "const" go in the typedef for constant member
functions?
3. Can the member functions be private even though they are
accessed in a vector created by the leaf class?
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library