![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 4
![]() |
Error...
Hi there again
![]() This is my new problem: I've this template: template <class T> class TArray
{
T **m_array;
unsigned m_nSize;
public:
class iterator;
friend class iterator;
class iterator
{
const TArray& t;
unsigned index;
public:
iterator( const TArray<T>& a, unsigned s = 0 ): t(a), index(s) {}
const T* const operator++() { return t[++index]; }
const T* const operator++(int) { return t[index++]; }
const T* const operator*() const { return t[index]; };
bool operator==( const iterator& r ) const { return ( t==r.t )? 1 : 0; }
bool operator!=( const iterator& r ) const { return !operator==( r ); }
friend ostream operator << (ostream& os, const iterator& it);
};
TArray();
virtual ~TArray();
void Insert (T* t);
const T* const Max() const;
const iterator begin() const;
const iterator end() const;
};Ye, ye... the definitions should be in diferent modules... Anyway, when i do this in the main: TArray<int> ar_int;
for ( unsigned i = 0; i < 10; i++ )
ar_int.Insert( new int(i) );
TArray<int>::iterator x(ar_int, 0); // this will point to the beggining
cout << *x << endl; // this should return the first value, the error is from hereIt gives me this error: 'operator+' not implemented in type 'TArray<int>' for arguments of type 'unsigned int' Why the 'operator+' is needed...??? Help here, guys... Thanks in advance ![]() |
|
|
|
|
|
#2 | |
|
Expert Programmer
Join Date: Jun 2005
Posts: 915
Rep Power: 4
![]() |
When I compile it I get
Quote:
Also note that your ++ operators should probably not return a different type, they should be returning the iterator, to be consistant with everyone else. |
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 4
![]() |
Ye... duh... Thanks bro
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|