vendredi 19 juillet 2019

Passing an element of array to a function in c++

I need to pass to a function an element of an array of strutcs. But I still can't.

Person is a nested struct.

//define Address structure
struct Address
{
    string Street;
    string City;
    string PostalCode;
};

//define Person structure
struct Person
{
    string Name;
    int Age;
    float Salary;
    struct Address Address;
};

// How I invoque the function
cout << "Address: " << ConcateAddress(persons[i].Address) << endl;


// Return a concatenated string with completed address of persion
string ConcateAddress(struct Address address)
{    
    string adressFinal=  address.Street + " " + address.PostalCode;
    if(!address.City.empty()){
        adressFinal = adressFinal + ", "+ address.City;
    }
}

Thank you, Ana

Aucun commentaire:

Enregistrer un commentaire