What does this error mean:

MyCAssignmentOprOverload\main.cpp...
main.cpp:29: error: name lookup of `i' changed for new ISO `for' scoping
] C:\Dev-main.cpp:27: error: using obsolete binding at `i'

Complete Compile C:\Dev-Cpp\MalikChapter3\MyCAssignmentOprOverload\MyCAssignmentOprOverload\main.cpp: 2 error(s), 1 warning(s)

Here is the header file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  #include <iostream>
using namespace std;

class cAssignmentOprOverload
{
	friend ostream& operator<<(ostream&, const cAssignmentOprOverload&);
	friend istream& operator>>(istream& , cAssignmentOprOverload& );
public:
    const cAssignmentOprOverload& operator=
					(const cAssignmentOprOverload& otherList);
//Overloads the assignment operator

    void print() const;
		//Function to print the list

    void insertEnd(int item);
		//Function to insert an item at the end of the list
		//Postcondition: if the list is not full, length++;
		//			  list[length] = item
		//		    if the list is full, outputs an
		//			  appropriate message

    void destroyList();
		//Function to destroy the list
		//Postcondition: length = 0; maxSize = 0; 
		//		    list = NULL

    cAssignmentOprOverload(int size = 10);
		//constructor
		//Postcondition: length = 0; maxSize = size; 
		//		    list is an array of size maxSize

private:
    int maxSize;
    int length;
    int *list;
};

the implementation:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <cassert>

#include "cAssignmentOprOverload.h"

using namespace std;

ostream& operator<<(ostream& osObject, const cAssignmentOprOverload& list)
{
	int i, maxSize;
	for(i = 0; i <= maxSize; i++)
	osObject<< i <<" ";
	return osObject;
}
istream& operator>>(istream& isObject, cAssignmentOprOverload& list)
{
	int i, maxSize ;
	for(i = 0; i <= maxSize; i++)
	isObject>> i;
	return isObject;
}
void cAssignmentOprOverload::print() const
{
	if(length == 0)
		cout<<"List is empty"<<endl;
	else
	{
		for(int i = 0; i < length; i++)
			cout<<list[i]<<" ";
		cout<<endl;
	}
}

void cAssignmentOprOverload::insertEnd(int item)
{
	if(length == maxSize)
		cout<<"List is full"<<endl;
	else
		list[length++] = item;
}

void cAssignmentOprOverload::destroyList()
{
	delete [] list;
	list = NULL;
	length = 0;
	maxSize = 0;
}

cAssignmentOprOverload::cAssignmentOprOverload(int size)
{
	length = 0;

	if(size <= 0)
		maxSize = 10;
	else
	maxSize = size;

	list = new int[maxSize];
	assert(list != NULL);
}


const cAssignmentOprOverload& cAssignmentOprOverload::operator= 
				(const cAssignmentOprOverload& otherList)
{
    if(this != &otherList)   //avoid self-assignment; Line 1
    {
		if(list != NULL)				   			
		
	destroyList();							

		maxSize = otherList.maxSize;		 		

	length = otherList.length;					

		if(maxSize != 0)							
		{		
			list = new int[maxSize];				

			assert(list != NULL);					


			for(int i = 0; i < length; i++)			

				list[i] = otherList.list[i];		
		}
		else						  				
			list = NULL;				   			
	}

	return *this;					   				
}


And the main()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include "cAssignmentOprOverload.h"

using namespace std;

int main() {
	
	using namespace std;
	
	cAssignmentOprOverload *myList, *otherList;
	cAssignmentOprOverload martin;
	
	//int *myList, *otherList;
	int arraySize ;
	
//	myList = new int[arraySize];
	cout <<"Enter the array size: ";
	cin >> arraySize;
	cout << endl;
	
	for(int i = 0; i < arraySize; i++) {
		cin >> myList[i];
	}
//	otherList[5];
		
		for (int i = 0; i < arraySize; i++) 
		otherList[i] = myList[i];
	cout << otherList[i] << " ";
	//myList->print();
	// use overloaded assignment (=) operator
  
   cout <<"\nAssigning myList to otherList:" << endl;
 
		myList = otherList;		   
	
	otherList->print();
	cout <<endl;
	for(int i = 0; i < arraySize; i++) {
		cout <<myList[i]<<" "<<endl;
	}	
	
}

I do not know what is obsolete and what has changed in ISO.
Maybe the lastest C++ IDE my help
It's not your compiler.

In the main snippet. only line 27 is within scope of the for loop. At line 28, i is out of scope.
I think you want lines 27 and 28 within {}.

I do not know what is obsolete and what has changed in ISO.
In the past the variable (i) defined in the header of the loop could be accessed outside of the loop. This behavior changed so that you cannot access i outside the loop anymore.
Enter the array size: 4

2
3
4
5
Press any key to continue . . .
After entering the 4 numbers. the program runs and it bombs out with the message:
[code]
MyCAssignmentOprOverload.exe has stopped working.
A problem caused the program to stop working correctly.
windows will close the program and notify yoy if a solution is available.

then there are two options to choose from.
Either Debug or Close program


1
2
3
4
5
6
7
8
9
10
11
12
13
14
Enter the array size: 4

2
3
4
5
Press any key to continue . . .
[code]
MyCAssignmentOprOverload.exe has stopped working.
A problem caused the program to stop working correctly.
windows will close the program and notify yoy if a solution is available.

then there are two options to choose from.
Either Debug or Close program

Both myList and otherList are uninitialized pointer. This causes undefined behavior and finally crashes.
I got my program to work 100% okay after properly initializing myList and otherList.
My program uses the for loops.
When I try to use the functions : insertEnd(item) and print() I get errors
1
2
3
        myList.insertEnd(65);
		
	myList.print();

Here are the errors:

[Error] main.cpp:26: error: request for member `insertEnd' in `myList', which is of non-class type `cAssignmentOprOverload*'
main.cpp:30: error: request for member `print' in `myList', which is of non-class type `cAssignmentOprOverload*'

The objective of the whole exercise was to write the main function to test the functions.

Please advise as to how to test these functions as declared in the header file and implemented in the .cpp file
When I try to use the functions : insertEnd(item) and print() I get errors
Well, within the code you showed you treat myList as an array. Either it is an array or not. You cannot use them in different ways.
Thank you very much to all of you!!!
My program worked very well after declaring *myList and *otherList
as objects of the class cAssignmentOprOverload by simply removing the '*' before *myList and *otherList and make them [code] myList and otherList

Topic archived. No new replies allowed.