dimanche 23 août 2020

Problem with initializing structure via new operator

Below are two variants of my program

#include <iostream>

struct customer{
    char fullname[35];
    double payment;
};

int main()
{
    customer alex{"Alex", 15};
    return 0;
}

#include <iostream>

struct customer{
    char fullname[35];
    double payment;
};

int main()
{
    customer* alex = new customer {"Alex", 15};
    return 0;
}

The first one works fine, but the second raises error:could not convert '{"Alex", 15}' from '' to 'customer'. What's the issue?

Aucun commentaire:

Enregistrer un commentaire