0

How come I can do this:

char sXSongs[20][30] = {"Song 1", "Song 2 (w/Blur)", "The End (It's Not Here Yet)"};
addAlbum(&list, "The Beatles", "Some Famous CD", 1960, sXSongs);

But not this:

addAlbum(&list, "The Beatles", "Some Famous CD", 1960, {"Song 1", "Song 2 (w/Blur)", "The End (It's Not Here Yet)"});

Is it impossible to initialize an array of cstrings inside a function call?

Here are some other tidbits of information:

album* list = NULL;
typedef struct album {
    char performer[20];
    char CDtitle[50];
    int year;
    char songs[20][30];
    struct album* prev;
    struct album* next;
} album;

2 Answers 2

1

No. It is possible to initialize an array when declaring it, not otherwise.

Sign up to request clarification or add additional context in comments.

Comments

1

You can't instantiate like that in C++.

It's possible (sort-of) in C# if you use anonymous types that you can create on the fly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.