0

Trying to compile a program, in my accounts.cpp I have 2 errors

accounts.cpp:240: error: name
   lookup of `a' changed for new ISO `for' scoping




accounts.cpp:234: error: 
    using obsolete binding at `a'

here's the code

bool cAccount::IsOnline( int acctnum )
{
    if (acctnum < 0) return false;

    map<int, acctman_st>::iterator iter_acctman;

    if ((iter_acctman = acctman.find(acctnum)) != acctman.end())
    {
        for (int a = 0; a < now; a++)
        {
            if (Client[a]->GetAccNum() == acctnum)
                break;
        }

        if (a == now)
        {
            SetOffline(acctnum);
            return false;
        }

any help would be awsome thanks :)

Edited by happygeek: fixed formatting

3
Contributors
2
Replies
5
Views
12 Years
Discussion Span
Last Post by frogn8r
Featured Replies
  • [QUOTE=Nicanor]Trying to compile a program, in my accounts.cpp I have 2 errorsp[quote]accounts.cpp:240: error: name lookup of `a' changed for new ISO `for' scoping accounts.cpp:234: error: using obsolete binding at `a'[/quote]here's the code [code]bool cAccount::IsOnline( int acctnum ) { if (acctnum < 0) return false; map<int, acctman_st>::iterator iter_acctman; if ((iter_acctman = … Read More

1

Trying to compile a program, in my accounts.cpp I have 2 errorsp

accounts.cpp:240: error: name
lookup of `a' changed for new ISO `for' scoping
accounts.cpp:234: error:
using obsolete binding at `a'

here's the code

bool cAccount::IsOnline( int acctnum )
  {
  	if (acctnum < 0) return false;
  
  	map<int, acctman_st>::iterator iter_acctman;
  
  	if ((iter_acctman = acctman.find(acctnum)) != acctman.end())
  	{
  		for (int a = 0; a < now; a++)
  		{
  			if (Client[a]->GetAccNum() == acctnum)
  				break;
  		}
  
  		if (a == now)
  		{
  			SetOffline(acctnum);
  			return false;
  		}

any help would be awsome thanks :)

I believe the diagnostic messages are telling you that the scope of a should only be within the for loop -- that is, it is not available outside the for loop. So if you are using it outside the for loop, you should not declare it within the for loop.

bool cAccount::IsOnline( int acctnum )
   {
   	if (acctnum < 0) return false;
   
   	map<int, acctman_st>::iterator iter_acctman;
   
   	if ((iter_acctman = acctman.find(acctnum)) != acctman.end())
   	{
   		int a;
   		for (a = 0; a < now; a++)
   		{
   			if (Client[a]->GetAccNum() == acctnum)
   				break;
   		}
   
   		if (a == now)
   		{
   			SetOffline(acctnum);
   			return false;
   		}
Comments
I moved my for (int row; ....) to declaring int row as protected variables of the class and this helped. Thanks.
0

I got this one :)
All you need is a final closing bracket at the bottom to finish your bool (function(?)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.