Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 29th, 2005, 6:06 PM   #1
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 4 -=PARADOX=- is on a distinguished road
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 here

It 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
-=PARADOX=- is offline   Reply With Quote
Old Nov 29th, 2005, 7:03 PM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 915
Rep Power: 4 The Dark is on a distinguished road
When I compile it I get
Quote:
error C2676: binary '[' : 'const TArray<T>' does not define this operator or a conversion to a type acceptable to the predefined operator
What is happening is that you haven't defined a [] operator, but you are using it in your iterator code. You compiler may be trying to do &t+index or somesuch in place of t[index], leadin to the error.

Also note that your ++ operators should probably not return a different type, they should be returning the iterator, to be consistant with everyone else.
The Dark is offline   Reply With Quote
Old Nov 29th, 2005, 7:16 PM   #3
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 4 -=PARADOX=- is on a distinguished road
Ye... duh... Thanks bro
-=PARADOX=- is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:42 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC