T
Thomas Matthews
Hi,
I have a Display class. I would like to write a function that takes a
range of objects and displays them. The range would be specified by
two forward iterators: start and end (one past start).
I created a base class "References" to test this concept. I want
the display function to process either a vector<References> or
a list<References>. However, in my compiler (Borland C++ Builder),
the std::list has a different iterator type than vector.
So how can I write a method to process a range of objects,
regardless of the container (assume that the fundamental requirement
for a range is forward iteration)?
struct Reference
{
string get_category(void) const;
string get_title(void) const;
};
class User_Interface
// : public Singleton<User_Interface>
// i.e. User_Interface is a Singleton
{
void display_references(?????);
};
User_Interface My_UI;
int main(void)
{
std::list<Reference> ref_list;
std::vector<Reference> ref_vector;
My_UI.display_references(ref_list.begin(),
ref_list.end());
My_UI.display_references(ref_vector.begin(),
ref_vector.end());
}
The above code is for illustrative purposes only and is
not meant to be compiled or run without errors.
--
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
I have a Display class. I would like to write a function that takes a
range of objects and displays them. The range would be specified by
two forward iterators: start and end (one past start).
I created a base class "References" to test this concept. I want
the display function to process either a vector<References> or
a list<References>. However, in my compiler (Borland C++ Builder),
the std::list has a different iterator type than vector.
So how can I write a method to process a range of objects,
regardless of the container (assume that the fundamental requirement
for a range is forward iteration)?
struct Reference
{
string get_category(void) const;
string get_title(void) const;
};
class User_Interface
// : public Singleton<User_Interface>
// i.e. User_Interface is a Singleton
{
void display_references(?????);
};
User_Interface My_UI;
int main(void)
{
std::list<Reference> ref_list;
std::vector<Reference> ref_vector;
My_UI.display_references(ref_list.begin(),
ref_list.end());
My_UI.display_references(ref_vector.begin(),
ref_vector.end());
}
The above code is for illustrative purposes only and is
not meant to be compiled or run without errors.
--
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