Ichki joylashgan funktsiyalar
Sinf funktsiyalarini sinf ichida yoki tashqarisida ta'riflash mumkindir. Misol uchun employee sinfida funktsiyalar sinf ichida ta'riflangandir:
class employee
{
public:
employee(char *name, char *position, float salary)
{
strcpy(employee::name, name);
strcpy(employee::position, position);
employee::salary = salary;
}
void show_employee(void)
{
cout << "Imya: " << name << endl;
cout << "Doljnost': " << position << endl;
cout << "Oklad: $" << salary << endl;
}
private:
char name [64];
char position[64];
float salary;
};
Bu holda funktsiyalar joylashtiriluvchi {inline) deb qaraladi. Funktsiya sinf tashqarisida ta'riflangan bo’lsa ularni inline funktsiya sifatida qarash uchun funktsiya ta'rifida inline so’zi aniq ko’rsatilgan bo’lishi kerak:
inline void employee::show_employee(void)
{
cout << "Imya: " << name << endl;
cout << "Doljnost': " << position << endl;
cout << "Oklad: $" << salary << endl;
}
Dostları ilə paylaş: |