Hi
I have a question regarding to iterators
I have a class which looks like this
Code:
class CardItem{
public:
CardItem(){
Card newcard(1, JOCKER);
subdeck.push_back(newcard);
Card newcard2(2, DIAMOND);
subdeck.push_back(newcard2);
};
virtual ~CardItem(){};
virtual void Shuffle(int flag);
//virtual void Sort(int flag);
vector<Card> Take(const int start, const int end);
/*
void Add(vector<Card> addon, int pos);
*/
protected:
bool fcompare(const Card& i, const Card& j);
private:
vector<Card> subdeck;
vector<Card> takeout;
};
and the implmentation of the vector<Card> Take() function is
Code:
vector<Card> CardItem::Take(const int start, const int end){
vector<Card>::iterator vStart = &subdeck[start];
vector<Card>::iterator vEnd = &subdeck[end];
for(int i = start; i <= end; ++i){
takeout[i-start] = subdeck[i];
}
subdeck.erase(vStart, vEnd);
}
the Card class is
Code:
class Card{
public:
Card(int val, suit_t suit);
virtual ~Card(){};
int getVal() const {return val;};
suit_t getSuit() const {return suit;};
private:
int val;
suit_t suit;
};
when I compile my code, the error message says
cardItem.cpp:20: error: conversion from `Card*' to non-scalar type `__gnu_cxx::__normal_iterator<Card*, std::vector<Card, std::allocator<Card> > >' requested
cardItem.cpp:21: error: conversion from `Card*' to non-scalar type `__gnu_cxx::__normal_iterator<Card*, std::vector<Card, std::allocator<Card> > >' requested
I understand that erase() requires two random access iterators, is there anyway to cast the normal iterator into random access iterator?
Cheers
Kai