473,385 Members | 1,856 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,385 software developers and data experts.

Issues with for loops

I have this function that looks like this:

bool is_descendant_of(const TreeT& ancestor) // line 316
{
for (TreeT* t = this; t; t = t->_parent) // line 318
if (t == &ancestor) // line 319
break; // line 320

return (t != NULL); // line 322
}

When I compile it with g++, I get this error message saying:

tree.cpp: In member function `bool gems::tree<T,
Alloc>::is_descendant_of(const
gems::tree<T, Alloc>&)':
tree.cpp:322: error: name lookup of `t' changed for new ISO `for'
scoping
tree.cpp:318: error: using obsolete binding at `t'

I'm not sure why it says this. I tried taking the t out of the return
statement and replacing t's value with a temporary variable, but that
didn't work either. I think it has do with the 318'th line.

Sep 5 '05 #1
4 2196

"twoeyedhuman1111" <tw**************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I have this function that looks like this:

bool is_descendant_of(const TreeT& ancestor) // line 316
{
for (TreeT* t = this; t; t = t->_parent) // line 318
if (t == &ancestor) // line 319
break; // line 320

return (t != NULL); // line 322
}

When I compile it with g++, I get this error message saying:

tree.cpp: In member function `bool gems::tree<T,
Alloc>::is_descendant_of(const
gems::tree<T, Alloc>&)':
tree.cpp:322: error: name lookup of `t' changed for new ISO `for'
scoping
The scope of the object 't' is that of the 'for' loop.
When the loop terminates, 't' is destroyed. Thus the
expression 't != NULL' is not valid, because there's
no object 't' in existence at that point.
tree.cpp:318: error: using obsolete binding at `t'

I'm not sure why it says this. I tried taking the t out of the return
statement and replacing t's value with a temporary variable, but that
didn't work either. I think it has do with the 318'th line.


Don't guess. Read a good (current) C++ text. See www.accu.org
for book reviews.

-Mike
Sep 5 '05 #2
twoeyedhuman1111 wrote:
I have this function that looks like this:

bool is_descendant_of(const TreeT& ancestor) // line 316
{
for (TreeT* t = this; t; t = t->_parent) // line 318
if (t == &ancestor) // line 319
break; // line 320

return (t != NULL); // line 322
}

When I compile it with g++, I get this error message saying:

tree.cpp: In member function `bool gems::tree<T,
Alloc>::is_descendant_of(const
gems::tree<T, Alloc>&)':
tree.cpp:322: error: name lookup of `t' changed for new ISO `for'
scoping
tree.cpp:318: error: using obsolete binding at `t'

I'm not sure why it says this. I tried taking the t out of the return
statement and replacing t's value with a temporary variable, but that
didn't work either. I think it has do with the 318'th line.


I'd write it as

bool is_descendant_of(const TreeT &ancestor)
{
TreeT *t = this;

while ((t != NULL) && (t != &ancestor)) { t = t->_parent; }
return t == &ancestor;
}
August
Sep 5 '05 #3
twoeyedhuman1111 wrote:
I have this function that looks like this:

bool is_descendant_of(const TreeT& ancestor) // line 316
{
for (TreeT* t = this; t; t = t->_parent) // line 318
if (t == &ancestor) // line 319 return true;
return false; }


Sep 5 '05 #4
Wow, I can't believe I didnt see that. I look at it now and say omg
what am I thinking.

Thank you very much for pointing this out

Sep 7 '05 #5

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

Similar topics

0
by: Merlin_1102 | last post by:
I have read previous posts on the gridbaglayout and none seem to answer my questions (sorry if any of these have been aske dI really did search and found one large thread which took me an hour to...
9
by: PyPK | last post by:
I was testing this piece of code and it takes about 24-30 seconds to do a look up on a list(m) of size 1000x1000 m -> list of size 1000x1000 import time print time.ctime() box = {} for r,row in...
15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
4
by: Steve Jorgensen | last post by:
I'm restarting this thread with a different focus. The project I'm working on now id coming along and will be made to work, and it's too late to start over with a new strategy. Still, I'm not...
1
by: Nikki | last post by:
I have a database, front and data backend, I have written in Access 97 and it has been chugging along for the last 6 years all with constant updates except for the last year with almost no...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
6
by: Peter Hans | last post by:
Hi, I developed two applications to test a flush() method in my application, but I am having some problems when running it at high baud rates (115200) I connected two computers using a...
17
by: Steve-O | last post by:
The following code works great in FireFox, Opera, Netscape, Safari, and Gecko, but NOT IE. Why? I tried using 'native' js with setInterval and setTimeout, but I get the same result. My IE...
1
by: bizt | last post by:
Hi, Im currently looking to move into using JSON for AJAX instead of returning from the server a string like the following: 12345{This is a text string{true I prefer objects because I dont...
4
by: phill86 | last post by:
Hi, Bare with me this is going to take some explaining and any help is much appreciated I have a form that stores details of sessions which include start/end date start/end time these...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
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...
0
marktang
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,...
0
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 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.