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 :)

Recommended Answers

All 2 Replies

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;
   		}
commented: 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(?)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.