C
ChasW
I have a class that manages a resource and provides a pointer to that
resource. For the sake of simplicity in asking this question:
class myClass
{
public:
myClass() { m_ptr = 0; }
~myClass();
unsigned char* getPtr { return m_ptr; }
unsigned char* operator+ ( long int n ) { return m_ptr + n; }
private:
m_ptr;
};
Notice that the class has an operator+ overload that returns a raw
pointer. This could be problematic for code that attempts to deduce
the type of an object of myClass type when seeing it used with the +
operator. Yet I want the functionality to be the same regardless, so I
need to give this class Random Access Iterator functionality.
I am not new to using iterators with STL containers and STL
algorithms, but what I want to do is either one of the following:
1) provide that set of functionality that makes my class an iterator
to its own resource, or
2) have myClass only manage the resource and have a separate class to
serve as an iterator to my class.
I am not sure exactly how to do either. What I need here is a
kickstart.
Do I inherit an iterator?
Do I add one as a member?
What would the prototype for overloading operator+ look like?
Would that overloaded operator+ return an iterator of unsigned char*
type or myClass type?
Thanks in advance for any helpful responses,
Charles Wilkins
resource. For the sake of simplicity in asking this question:
class myClass
{
public:
myClass() { m_ptr = 0; }
~myClass();
unsigned char* getPtr { return m_ptr; }
unsigned char* operator+ ( long int n ) { return m_ptr + n; }
private:
m_ptr;
};
Notice that the class has an operator+ overload that returns a raw
pointer. This could be problematic for code that attempts to deduce
the type of an object of myClass type when seeing it used with the +
operator. Yet I want the functionality to be the same regardless, so I
need to give this class Random Access Iterator functionality.
I am not new to using iterators with STL containers and STL
algorithms, but what I want to do is either one of the following:
1) provide that set of functionality that makes my class an iterator
to its own resource, or
2) have myClass only manage the resource and have a separate class to
serve as an iterator to my class.
I am not sure exactly how to do either. What I need here is a
kickstart.
Do I inherit an iterator?
Do I add one as a member?
What would the prototype for overloading operator+ look like?
Would that overloaded operator+ return an iterator of unsigned char*
type or myClass type?
Thanks in advance for any helpful responses,
Charles Wilkins