Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > operator-overloading of nested class inside a template class

Reply
Thread Tools

operator-overloading of nested class inside a template class

 
 
Gerhard Pfeiffer
Guest
Posts: n/a
 
      09-14-2006
Hi,

I'm trying to implement a data-structure and have an iterator for it. Now I've
got a problem impleneting the operator+. I tried to isolate the problem:

template<int DIM, typename T> class data_structure {
private:
int data[256];
public:
class iterator {
public:
int index;
};
};

template<int DIM, typename T>
data_structure<DIM, T>::iterator
operator+(data_structure<DIM, T>::iterator it, int n) {
iterator ret();
ret.index = it.index + n;
}

and g++ gives me this error:
bla.cpp:13: error: expected constructor, destructor, or type conversion before
'operator'

I just don't see, what I'm doing wrong here. Any hints would be appreciated.

Ciao,
Gerhard
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-14-2006
Gerhard Pfeiffer wrote:
> Hi,
>
> I'm trying to implement a data-structure and have an iterator for it.
> Now I've got a problem impleneting the operator+. I tried to isolate
> the problem:
>
> template<int DIM, typename T> class data_structure {
> private:
> int data[256];
> public:
> class iterator {
> public:
> int index;
> };
> };
>
> template<int DIM, typename T>
> data_structure<DIM, T>::iterator
> operator+(data_structure<DIM, T>::iterator it, int n) {
> iterator ret();

^^^^^^^^^^^^^^^^^^^^^^
This is a declaration of a function. Drop the parentheses.

> ret.index = it.index + n;
> }
>
> and g++ gives me this error:
> bla.cpp:13: error: expected constructor, destructor, or type
> conversion before 'operator'
>
> I just don't see, what I'm doing wrong here. Any hints would be
> appreciated.


Read the FAQ. All of it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      09-14-2006
On 14 Sep 2006 18:04:59 GMT in comp.lang.c++, Gerhard Pfeiffer
<(E-Mail Removed)> wrote,
>template<int DIM, typename T>
>data_structure<DIM, T>::iterator
>operator+(data_structure<DIM, T>::iterator it, int n) {
> iterator ret();
> ret.index = it.index + n;
>}
>


iterator is a type dependent on the template parameter; "typename"
is required.

template<int DIM, typename T>
typename data_structure<DIM, T>::iterator
operator+(typename data_structure<DIM, T>::iterator it, int n) {
iterator ret();
ret.index = it.index + n;
}


 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      09-14-2006
David Harmon wrote:
> On 14 Sep 2006 18:04:59 GMT in comp.lang.c++, Gerhard Pfeiffer
> <(E-Mail Removed)> wrote,
>> template<int DIM, typename T>
>> data_structure<DIM, T>::iterator
>> operator+(data_structure<DIM, T>::iterator it, int n) {
>> iterator ret();
>> ret.index = it.index + n;
>> }
>>

>
> iterator is a type dependent on the template parameter; "typename"
> is required.
>
> template<int DIM, typename T>
> typename data_structure<DIM, T>::iterator
> operator+(typename data_structure<DIM, T>::iterator it, int n) {
> iterator ret();


'ret' is still a function here...

> ret.index = it.index + n;
> }


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class nested inside a template class as template function argument type claudiu C++ 3 04-01-2011 01:02 PM
Class nested inside a template class as template function argument type claudiu C Programming 2 04-01-2011 12:10 PM
problem with a function template returning a private nested class ofa class template ymost@hotmail.com C++ 2 12-28-2008 10:43 AM
how to partially specialize a template class nested inside anothertemplate class? huili80@gmail.com C++ 5 06-22-2008 01:47 PM
Nested friend class in nested template problem tonvandenheuvel@gmail.com C++ 3 12-07-2007 03:02 PM



Advertisments