V
V
Valeria Tkacheva2019-12-14 01:10:34
Visual Studio Code
Valeria Tkacheva, 2019-12-14 01:10:34

How to fix "cout is not unambiguous" error?

It also gives the error 'this variable does not contain a storage class or type specifier' What 's the
problem ? class country { public: country(); country(char* aname , double at_winter, double at_spring,double at_summer,double at_autumn); country(const country&CONTRY); ~country(); char* Returnname() { return name; }; double ReturnT_Winter() { return t_winter; }; double ReturnT_Spring() { return t_spring; }; double ReturnT_Summer() { return t_summer; }; double ReturnT_Autumn() { return t_autumn; };
friend ostream& operator<<(ostream& OUT, const country& COUNTRY);
friend istream& operator>>(istream& IN, country& COUNTRY);
country& operator=(const country& COUNTRY);
protected:
char*name;
double t_winter, t_spring, t_summer, t_autumn;
};
class NewCountry : public country {
public:
NewCountry();
NewCountry(char* aname, double at_winter, double at_spring, double at_summer, double at_autumn, int apolusharie);
NewCountry(const NewCountry& COUNTRY);
~NewCountry();
unsigned short int gpolusharie() { return polusharie; };
string sReturnpolushary();
friend ostream& operator<<(ostream& OUT,
friend istream& operator>>(istream& IN, NewCountry& COUNTRY);
NewCountry& operator=(const NewCountry& COUNTRY);
private:
unsigned short int polarity;
};
country::country()
{
name = NULL;
t_winter = NULL;
t_spring = NULL;
t_summer = NULL;
t_autumn = NULL;
};
country::country(char* aname, double at_winter, double at_spring, double at_summer, double at_autumn) :
name(new char[strlen(aname) + 1])
{
strcpy_s(name, strlen(aname) + 1, aname);
t_winter = at_winter;
t_spring = at_spring;
t_summer = at_summer;
t_autumn = at_autumn;
};
country::country(const country& COUNTRY) :
name(new char[strlen(COUNTRY.name) + 1])
{
strcpy_s(name, strlen(COUNTRY.name) + 1, COUNTRY.name);
t_winter = COUNTRY.t_winter;
t_spring = COUNTRY.t_spring;
t_summer = COUNTRY.t_summer;
t_autumn = COUNTRY.t_autumn;
};
country::~country()
{
delete[] name;
};
ostream& operator<<(ostream& Out, const country& COUNTRY)
{
Out << "\nCOUNTRY: " << COUNTRY.name << "\nTEMPERATURE IN WINTER" << COUNTRY.t_winter << "\nTEMPERATURE IN SPRING" << COUNTRY.t_spring << "\nSUMMER TEMPERATURE" << COUNTRY.t_summer << "
istream& operator>>(istream& In, country& COUNTRY)
{
char TEMP[123];
In >> TEMP >> COUNTRY.t_winter >> COUNTRY.t_spring >> COUNTRY.t_summer >> COUNTRY.t_autumn;
delete[] COUNTRY.name;
COUNTRY.name = new char[strlen(TEMP) + 1];
strcpy_s(COUNTRY.name, strlen(TEMP) + 1, TEMP);
return In;
};
country& country::operator=(const country& COUNTRY) {
if (this == &COUNTRY) return *this;
delete[]name;
name = new char[strlen(COUNTRY.name) + 1];
strcpy_s(name, strlen(COUNTRY.name) + 1, COUNTRY.name);
name = COUNTRY.name;
t_winter = COUNTRY.t_winter;
t_spring = COUNTRY.t_spring;
t_autumn = COUNTRY.t_autumn;
return *this;
};
NewCountry::NewCountry() :
country()
{
polusharie = NULL;
};
NewCountry::NewCountry(char* aname, double at_winter, double at_spring, double at_summer, double at_autumn, int apolusharie) :
country(aname,at_winter, at_spring, at_summer, at_autumn)
{
polusharie = apolusharie;
};
NewCountry::NewCountry(const NewCountry& COUNTRY) :
country(COUNTRY)
{
polusharie = COUNTRY.polusharie;
};
NewCountry::~NewCountry()
{
delete[]name;
};
string NewCountry::sReturnpolusharie() {
if (polusharie == 1) return "northern";
if (polusharie == 2) return "southern";
if (polusharie == 3) return "on both sides of the equator";
return "!!!ERROR: no data!!!";
};
ostream& operator<<(ostream& Out, const NewCountry& COUNTRY)
{
Out << "\nCOUNTRY: " << COUNTRY.name << "\nTEMPERATURE IN WINTER" << COUNTRY.t_winter << "\nTEMPERATURE IN SPRING" << COUNTRY.t_spring << "\nTEMPERATURE IN SUMMER" << COUNTRY.t_summer << "\nTEMPERATURE IN AUTUMN" << COUNTRY.t_autumn;
Out << "\nPOSITION RELATIVE TO THE EQUATOR: ";
if (COUNTRY.polusharie == 1) Out << "
};
istream& operator>>(istream& In, NewCountry& COUNTRY)
{
char TEMP[123];
In >> TEMP >> COUNTRY.t_winter >> COUNTRY.t_spring >> COUNTRY.t_summer >> COUNTRY.t_autumn >> COUNTRY.polusharie;
delete[] COUNTRY.name;
COUNTRY.name = new char[strlen(TEMP) + 1];
strcpy_s(COUNTRY.name, strlen(TEMP) + 1, TEMP);
return In;
};
NewCountry& NewCountry::operator=(const NewCountry& COUNTRY) {
if (this == &COUNTRY) return *this;
delete[]name;
name = new char[strlen(COUNTRY.name) + 1];
strcpy_s(name, strlen(COUNTRY.name) + 1, COUNTRY.name);
t_winter = COUNTRY.t_winter;
t_spring = COUNTRY.t_spring;
t_summer = COUNTRY.t_summer;
t_autumn = COUNTRY.t_autumn;
polusharie = COUNTRY.polusharie;
return *this;
};
void main() {
setlocale(LC_ALL, "Russian");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
intN;
double winter = lol[0].ReturnT_Winter;
double summer = lol[0].ReturnT_Summer;
NewCountry* lol;
cout << "NUMBER OF COUNTRIES: ";
cin >> N;
lol = new NewCountry[N];
cout << "Enter the data\nName of the country, temperature in winter, spring and summer, in which hemisphere it is located (1 - northern, 2 - southern, 3 - on both sides of the equator):\n\n";
for (int i = 0; i < N; i++) cin >> lol[i];
for ( int i = 0; i < N; i++)
{
if (winter < lol[i].ReturnT_Winter())
winter = lol[i].ReturnT_Winter();
if (summer > lol[i].ReturnT_Summer ())
summer = lol[i].ReturnT_Summer();
}
};
cout << "\nCheck operator =\n";
lol[0] = lol[1];
cout << lol[0] << endl;
cout << lol[1] << endl;
cout << "\nCheck copy constructor\n";
NewCountry Copy(lol[2]);
cout << Copy << endl;
cout << lol[2] << endl;
delete[] lol;
system("pause");
};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question