How to Return Array Elements with a Function in C++

preview_player
Показать описание
⏩ Get the C++ Better Explained Book for Just $1:
Рекомендации по теме
Комментарии
Автор

📞 Struggling with C++? Let's Fix That on a Free Call!

cbetterexplained
Автор

It's works!!

I tried with this code. Thanks!
(User is a class than I created)

auto get_users(){
static User* arr[4];
arr[0] = new User;
arr[1] = new User;
arr[2] = new User;
arr[3] = new User;
arr[4] = new User;

arr[0]->set_data("Naomi", 29);
arr[1]->set_data("Tina", 21);
arr[2]->set_data("Yoshino", 25);
arr[3]->set_data("Kurumi", 18);
arr[4]->set_data("Kotori", 19);


return arr;

}

int main()
{
// User * user1 = new User;
auto database = get_users();

cout << database[0]->name << endl;


}

console => Naomi

bbl
welcome to shbcf.ru