In line using std::list::iterator the compiler gives an message "Error: a class-qualified name is not allowed. I am unsure what is the problem? Can someone expand on the compilers problem with my code.
#include <iostream>
#include <list>
using std::cout;
using std::endl;
using std::list;
using std::list<int>::iterator;
int main( )
{
list<int> listObject;
for (int i = 1; i <= 3; i++)
listObject.push_back(i);
cout << "List contains:\n";
iterator iter;
for (iter = listObject.begin( ); iter != listObject.end( ); iter++)
cout << *iter << " ";
cout << endl;
cout << "Setting all entries to 0:\n";
for (iter = listObject.begin( ); iter != listObject.end( ); iter++)
*iter = 0;
cout << "List now contains:\n";
for (iter = listObject.begin( ); iter != listObject.end( ); iter++)
cout << *iter << " ";
cout << endl;
return 0;
}
You can't bring a name from the class scope into namespace scope with using
directive. You can only be using
a name defined at namespace scope, in a different namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With