Re: Compilation errors in a vector problem
Ankur Arora wrote:
While coding an algorithm for the following problem, there are a few
compilation errors that I don't completely understand. The errors
are:-
error C2839: invalid return type 'Human **' for overloaded 'operator -
'
error C2039: 'PrintFamilyTree' : is not a member of
'std::_Vector_iterator<_Ty,_Alloc>'
1> with
1> [
1> _Ty=Human *,
1> _Alloc=std::allocator<Human *>
1> ]
[..]
void PrintFamilyTree(const short& generation)
{
printf("Name : %s Generation = %d\n", m_Name.c_str(),generation);
vector<Human*>::iterator it;
for (it = this.begin(); it< this.end() ;it++)
What's "this" doing here? As I understand the language rules, the line
above should not compile. Or is that function inside a class
definition? Then it still not supposed to compile since 'this' is a
pointer and with a pointer '.' cannot be used (pointers don't have members).
Also, it is more idiomatic to use != when comparing an iterator to the
end of the container being iterated, not <.
{
it->PrintFamilyTree(generation+1);
}
}
-----------------------------------------------------------------------------------------------------------
The problem occurs at the line:-
it->PrintFamilyTree(generation+1);
Are you sure?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask