The following program is showing error:
#include<conio.h>
#include<iostream.h>
int count = 0;
class alpha
{
public:
alpha()
{
count++;
cout<<"\n Number of objects created "<<count;
}
~alpha()
{
cout<<"\n Number of object destroyed"<<count;
count--;
}
};
int main
{
cout<<" inside main ";
alpha a1, a2, a3, a4;
{
cout<<"\n Block 1 ";
alpha A5;
}
{
cout<<"\n Block 2 ";
alpha a6;
}
cout<<" main again ";
return 0;
}
Line 11: error: reference to ‘count’ is ambiguous compilation terminated due to -Wfatal-errors.
There is no header
<iostream.h>in standard C++. Use the header<iostream>which has names instdnamespace, thus not polluting the global namespace with names ascount.Don’t forget to use
std::cin,std::coutetc. from now on.If your compiler doesn’t recognize
<iostream>, throw it away and get a new one. Visual Studio Express, for one, is free and easy to use, though not extremely standards-compliant at the moment, but that should not be a big issue for you.