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 Tclass 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 3 2222
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 Tclass 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
On 14 Sep 2006 18:04:59 GMT in comp.lang.c++, Gerhard Pfeiffer
<gp@bnbt.dewrote,
>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;
}
David Harmon wrote:
On 14 Sep 2006 18:04:59 GMT in comp.lang.c++, Gerhard Pfeiffer
<gp@bnbt.dewrote,
>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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ··········· sylvain |
last post by:
hello,
what does the operator |= mean?
I saw it in a script :
$output = "png";
$style = BCS_ALIGN_CENTER;
$style |= ($output == "png" ) ? BCS_IMAGE_PNG : 0;
|
by: Richard Hayden |
last post by:
Hi,
I have the following code for example:
/**********************************/
#include <iostream>
class C1 {
public:
|
by: Alex Vinokur |
last post by:
Why is it ambiguous?
------ foo.cpp ------
struct Foo
{
Foo operator* (Foo) { return Foo(); }
Foo operator* (int) const { return Foo(); }
Foo () {}
Foo (int) {}
};
|
by: lutorm |
last post by:
Hi everyone,
I'm trying to use istream_iterators to read a file consisting of pairs
of numbers. To do this, I wrote the following:
#include <fstream>
#include <vector>
#include <iterator>
...
|
by: mux |
last post by:
Hi
I found out that the following piece of code throws an error.
1 #include "stdio.h"
2
3 int main()
4 {
5 int a,b;
6 a= 10;
|
by: Anoob |
last post by:
Can we consider () unary operator when calling a function, in exps eq.
f(), ( 1 + 2). But when we call function f( 10 ) it is a binary
operator. Even if we pass f( 10, 20) as we are using ,...
|
by: Norman Diamond |
last post by:
In an antique obsolete version of MFC, a CString expression could be
subscripted in order to retrieve one element.
Visual Studio 2005 defines CSimpleStringT::operator. At first glance it
looks...
|
by: Ranganath |
last post by:
Why is throw keyword considered as an operator?
|
by: Martin T. |
last post by:
Hello.
I tried to overload the operator<< for implicit printing of wchar_t
string on a char stream.
Normally using it on a ostream will succeed as
std::operator<<<std::char_traits<char>
will...
|
by: C++Liliput |
last post by:
I have a custom String class that contains an embedded char* member.
The copy constructor, assignment operator etc. are all correctly
defined. I need to create a map of my string (say a class...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |