Програмування на С і С++. Вказівник this, Детальна інформація
Програмування на С і С++. Вказівник this
int Number; // Порядковий номер елемента.
double Meaning; // Значення елемента.
public:
//Конструктор:
cell(double Meaning = 0.0)
{ // Змінюємо значення статичного компонента:
Amount++;
this -> Number = Amount;
// Компонент і однойменний параметр:
this -> Meaning = Meaning; }
// Висновок зведень про об'єкт і кількість елементів:
void display (void)
{
// Зайві this:
cout << "\nNumber = " << this->Number;
cout << " Amount = " << this->Amount;
cout << " Meaning = " << this->Meaning;
}
};
// Ініціалізація статичного компонента:
int cell::Amount = 0;
void main(void)
{ cell A; // Об'єкт зі значенням, що умовчується.
A.display();
cell B(200.0);
cell C(300.0);
B.display();
C.display();
}
Результат виконання програми:
double Meaning; // Значення елемента.
public:
//Конструктор:
cell(double Meaning = 0.0)
{ // Змінюємо значення статичного компонента:
Amount++;
this -> Number = Amount;
// Компонент і однойменний параметр:
this -> Meaning = Meaning; }
// Висновок зведень про об'єкт і кількість елементів:
void display (void)
{
// Зайві this:
cout << "\nNumber = " << this->Number;
cout << " Amount = " << this->Amount;
cout << " Meaning = " << this->Meaning;
}
};
// Ініціалізація статичного компонента:
int cell::Amount = 0;
void main(void)
{ cell A; // Об'єкт зі значенням, що умовчується.
A.display();
cell B(200.0);
cell C(300.0);
B.display();
C.display();
}
Результат виконання програми:
The online video editor trusted by teams to make professional video in
minutes
© Referats, Inc · All rights reserved 2021