F
food4uk
Dear all :
I am not good at programming, please give a hand.
My data structure is very similar as an array. I actually can use the
std::vector as container to organize my data objects. However, the
behaviours of std::vector::iterator can not meet my requirements. I
need to redefine the vector::iterator's behavious such as ++. It means
"next position in the object sequence" in STL but now I redefine it to
mean "next position within a 2-d range in the object sequence" (my data
is 2d data). The 2-d range get defined when an iterator get
initialized. Therefore, I think I have to create my own container
class and iterator class.
To reduce my work, I inherit my container class from the std::vector
privately, and try to use the vector::begin(), as it is important for
me to have a begin() in my container, like this:
using std::vector
class container:rivate vector<DATATYPE>
{
public:
using vector<DATATYPEl>::begin;
}
however, I found that the begin() I got from here returns a
vector:iterator type iterator, which is not what I want. I would like
to see that the container::begin() can return a myIterator type
iterator which enables me to use the customerized definition of its
behivours (such as the definition of "++ "above).
To to that, I make the container::begin() like this :
#inlcude myIterator.h
class container:rivate vector<DATATYPE>
{
private:
myIterator pIter;
public:
.....
myIterator begin()
{
*pIter=vector<DATATYPE>::front();
return pIter;
}
}
// in myIterator.h , I have:
#include DATATYPE.h
class myIterator {
private:
DATATYPE* current;
.....................
public:
DATATYPE& operator*()
{
return *current;
}
}
I am not sure if it is the correct way to do that. Any one can give me
a hand is highly appreciated.
Thanks in advance.
Sheldon
I am not good at programming, please give a hand.
My data structure is very similar as an array. I actually can use the
std::vector as container to organize my data objects. However, the
behaviours of std::vector::iterator can not meet my requirements. I
need to redefine the vector::iterator's behavious such as ++. It means
"next position in the object sequence" in STL but now I redefine it to
mean "next position within a 2-d range in the object sequence" (my data
is 2d data). The 2-d range get defined when an iterator get
initialized. Therefore, I think I have to create my own container
class and iterator class.
To reduce my work, I inherit my container class from the std::vector
privately, and try to use the vector::begin(), as it is important for
me to have a begin() in my container, like this:
using std::vector
class container:rivate vector<DATATYPE>
{
public:
using vector<DATATYPEl>::begin;
}
however, I found that the begin() I got from here returns a
vector:iterator type iterator, which is not what I want. I would like
to see that the container::begin() can return a myIterator type
iterator which enables me to use the customerized definition of its
behivours (such as the definition of "++ "above).
To to that, I make the container::begin() like this :
#inlcude myIterator.h
class container:rivate vector<DATATYPE>
{
private:
myIterator pIter;
public:
.....
myIterator begin()
{
*pIter=vector<DATATYPE>::front();
return pIter;
}
}
// in myIterator.h , I have:
#include DATATYPE.h
class myIterator {
private:
DATATYPE* current;
.....................
public:
DATATYPE& operator*()
{
return *current;
}
}
I am not sure if it is the correct way to do that. Any one can give me
a hand is highly appreciated.
Thanks in advance.
Sheldon