473,378 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how return a iterator?

VolumeType::ISetType::iterator findFirstIteratorMarked(const
VolumeType::ISetType::iterator & it,const
VolumeType::ISetType::iterator & e_it)
{
VolumeType::ISetType::iterator _it=it;
while (_it!=e_it)
{
if ((*_it).mark) return _it;
else _it++;
}
}
Hi,

I would like do a function that give a iterator to vector stl return
the first element after of iterator where
the field mark is true.How can I do it?
e_it is v.end() where v is a stl vector.
I get compiler error.....

Mar 17 '07 #1
6 3101
On Mar 17, 9:04 pm, "antani" <antani8...@yahoo.itwrote:
VolumeType::ISetType::iterator findFirstIteratorMarked(const
VolumeType::ISetType::iterator & it,const
VolumeType::ISetType::iterator & e_it)
{
VolumeType::ISetType::iterator _it=it;
while (_it!=e_it)
{
if ((*_it).mark) return _it;
else _it++;
}

}

I get compiler error.....
You have not declared any return statement outside the 'while' loop
which might be the reason for the error you get.

either add a return statement outside the loop or if you are using
microsoft vc,declare your function as '__declspec(noreturn)'.
Hi,

I would like do a function that give a iterator to vector stl return
the first element after of iterator where
the field mark is true.How can I do it?
e_it is v.end() where v is a stl vector.
#include <algorithm>

and use 'std::find_if' like this:

/*assuming that 'VolumeType::ISetType::iterator' points to objects of
type 'vtype'*/

typedef std::vector<vtypemy_vec;

bool Ismarked(const my_vec::value_type& x){/*
my_vec::value_type==vtype */
return x.mark;
};

bool Is_not_marked(const vtype& x){/* my_vec::value_type==vtype */
return !x.mark;
};

{//somewhwere in your code:
const VolumeType::ISetType::iterator iter;
iter=std::find_if(v.begin(),v.end(),Ismarked);/*find first marked
element*/

iter=std::find_if(v.begin(),v.end(),Is_not_marked) ;/*find first
none-marked element*/
};
Mar 17 '07 #2
terminator wrote:
On Mar 17, 9:04 pm, "antani" <antani8...@yahoo.itwrote:
>VolumeType::ISetType::iterator findFirstIteratorMarked(const
VolumeType::ISetType::iterator & it,const
VolumeType::ISetType::iterator & e_it)
{
VolumeType::ISetType::iterator _it=it;
while (_it!=e_it)
{
if ((*_it).mark) return _it;
else _it++;
}

}

I get compiler error.....
You have not declared any return statement outside the 'while' loop
which might be the reason for the error you get.

either add a return statement outside the loop or if you are using
microsoft vc,declare your function as '__declspec(noreturn)'.
If you declare a function as '__declspec(noreturn)', wouldn't that mean
that the returned value will either be a valid iterator or an invalid
one? If so, then you wouldn't be able to tell them apart.

Return the e_it instead on failure, or use the algorithms that
terminator used.
Adrian
--
__________________________________________________ ___________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
Mar 18 '07 #3
You have not declared any return statement outside the 'while' loop
which might be the reason for the error you get.

template <class MeshType, class VolumeType>
class TrivialWalker
{

VolumeType::ISetType::iterator findFirstIteratorMarked(const
VolumeType::ISetType::iterator it,const
VolumeType::ISetType::iterator e_it)
{
VolumeType::ISetType::iterator _it=it;
while (_it!=e_it)
{
if ((*_it).mark) return _it;
else _it++;
}
return e_it;
}

......
}
I include this class.....

class MIVolume
{
public:

typedef typename InterceptType I_Type;
typedef typename InterceptSet<I_TypeISetType;

.....
}
I get this errors:

error C2146: syntax error : missing ';' before identifier
'findFirstIteratorMarked'
error C2061: syntax error : identifier 'iterator'

Mar 18 '07 #4
On 18 Mar, 20:09, "antani" <antani8...@yahoo.itwrote:

AFAICS..
You need to work out how typename keyword is needed in your template
code and not in non template code....
>
template <class MeshType, class VolumeType>
class TrivialWalker
{
// Do need typename here ..
VolumeType::ISetType::iterator findFirstIteratorMarked(const
VolumeType::ISetType::iterator it,const
VolumeType::ISetType::iterator e_it)
// e.g...
typename VolumeType::ISetType::iterator findFirstIteratorMarked(const
typename VolumeType::ISetType::iterator it,const
typename VolumeType::ISetType::iterator e_it)
{
//##########
// typename ....
VolumeType::ISetType::iterator _it=it;
//#########

<...>
I include this class.....

class MIVolume
{
public:
//################################
// dont need typename here AFAICS...
typedef typename InterceptType I_Type;
typedef typename InterceptSet<I_TypeISetType;
//########################
I get this errors:

error C2146: syntax error : missing ';' before identifier
'findFirstIteratorMarked'
error C2061: syntax error : identifier 'iterator'
Yep.. confusing error messages ;-)

regards
Andy Little

Mar 19 '07 #5
On 19 Mar, 06:07, "kwikius" <a...@servocomm.freeserve.co.ukwrote:
// Do need typename here ..
VolumeType::ISetType::iterator findFirstIteratorMarked(const
VolumeType::ISetType::iterator it,const
VolumeType::ISetType::iterator e_it)

// e.g...
typename VolumeType::ISetType::iterator findFirstIteratorMarked(const
typename VolumeType::ISetType::iterator it,const
typename VolumeType::ISetType::iterator e_it)
//OTOH Just use a typedef (note again 'typename' use) :

typedef typename VolumeType::ISetType::iterator iterator;
// now can use typedef...
iterator findFirstIteratorMarked(const
iterator it,const
iterator e_it)
>
{

//##########
// etc...
iterator _it=it;
regrads
Andy Little
Mar 19 '07 #6
"antani" <an********@yahoo.itwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
>
>You have not declared any return statement outside the 'while' loop
which might be the reason for the error you get.


template <class MeshType, class VolumeType>
class TrivialWalker
{

VolumeType::ISetType::iterator findFirstIteratorMarked(const
VolumeType::ISetType::iterator it,const
VolumeType::ISetType::iterator e_it)
{
VolumeType::ISetType::iterator _it=it;
while (_it!=e_it)
{
if ((*_it).mark) return _it;
else _it++;
}
return e_it;
}

.....
}
I include this class.....

class MIVolume
{
public:

typedef typename InterceptType I_Type;
typedef typename InterceptSet<I_TypeISetType;

....
}

I get this errors:

error C2146: syntax error : missing ';' before identifier
'findFirstIteratorMarked'
error C2061: syntax error : identifier 'iterator'
This error, "missing ';' before identifier ..." means, if you actually
didn't miss an ;, that the compiler didn't understand the token BEFORE the
identifier. So we look at your code.

VolumeType::ISetType::iterator findFirstIteratorMarked(const

We see where findFirstIteraotrMarked is, look before it, so the compiler
can't figure out what
VolumeType::ISetType::iterator is. Maybe it doesn't know what VolumeType
is. Maybe it doesn't know what ISetType is.

We see that VolumeType is a template parameter, so that's probably not it.
We don't see ISetType passed. So, where is ISetType defined? It most
likely isn't find it for that class, maybe you didn't define it correctly,
or before it was needed.
Mar 19 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Huibuh | last post by:
I start hating RETURN!!! list<happy> //#include <list>// is searched via iterator (ptr) so long until the argument "number" of the class "happy" is equal now. The function "findhappy" works...
5
by: Bob | last post by:
Hi, I have a std::vector, say myVec, of some user defined object, say myOb. In my code, I have a function that searches myVec for a particular myOb. The way I was doing this was searching...
3
by: learning_C++ | last post by:
I hope to use template. in my code I hope to sum the vector<int> and vector<double>. But there are several errors: sumtemplate.cpp:6: error: ISO C++ forbids declaration of `sum' with no type...
11
by: snnn | last post by:
On the book <Generic Programming and the STL>( Matthew . H . Austern ),this function is defined as iterator set::begin() const. However, why should a const object returns a non-const iterator?...
1
by: Marcin Kaliciński | last post by:
Hi, map::erase(iterator) and map::erase(iterator, iterator). In STL shipped with MSVC return value of these functions is iterator. In gcc 3.3 it is void. Which one is conforming? cheers,...
3
by: Allerdyce.John | last post by:
Hi, When I return an iterator, should I return an iterator, or should I return a reference to the iterator? for example: vector<A> aVector; Should it be: vector<A>::Iterator...
6
by: TOMERDR | last post by:
Hi,i am new to stl and i have a question regarding iterators I have class day contains a map of appointments: map<time_t,Appointment> m_Appointments; I would like to write a function...
2
by: Steve Richter | last post by:
very confused on how to implement the IEnumerable and IEnumerator interfaces on a generic type. I understand I should just use a foreach loop in the GetEnumerator method and use "yield return",...
3
by: Jess | last post by:
Hello, The C++ reference says the return result of "copy" is an output iterator. I'm wondering how I can assign the returned iterator to some other iterator. I tried int main(){ string...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.