Why am i getting a “'initializing': cannot convert from 'initializer list' to '_Objty'” error in C++?
I'm creating a program where the user has to identify certain chords. I'm using SDL to render text and shapes onto a GUI and SDL_Mixer to load sounds. The program will require the user to play a sound and guess the sound that was played using a series of options. The rest of the program works fine. However, the issue occurred once i tried to implement a way to load and work with sounds. All of the code below is encapsulated in a class.
I tried commenting out certain parts of the code and i found that the error occurs when i try to add the sounds to the vector using emplace_back(). The error occurs at line 881 of a file called xmemory0. This is the code where the error occurs "_Objty(_STD forward<_Types>(_Args)...);".
This code has it's access specifier defined as private
//Container to hold the sound data
std::vector<Sound*>Sounds;
//Container to hold the randomly selected sounds;
std::vector<Sound*> randomSounds;
Sound* aMinor{ new Sound{} };
Sound* aMajor{ new Sound{} };
Sound* a7{ new Sound{} };
Sound* aMajor7{ new Sound{} };
Sound* cMajor{ new Sound{} };
Sound* dMajor{ new Sound{} };
Sound* dMinor{ new Sound{} };
Sound* eMajor{ new Sound{} };
Sound* eMinor{ new Sound{} };
Sound* eMinor7{ new Sound{} };
Sound* eMajor7{ new Sound{} };
Sound* fMajor{ new Sound{} };
Sound* fMinor{ new Sound{} };
Sound* gMajor{ new Sound{} };
//These are the pointers for the randomly selected sounds
Sound* randomSoundLeft;
Sound* randomSoundMiddle;
Sound* randomSoundRight;
//Pointer for the sound which the user will play
Sound* currentPlayingSound;
This code is defined within a 'load data' method
//Add sounds to vector
Sounds.emplace_back(aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor);
//Load sounds
if (!aMinor->loadSound("Chords/A_minor.wav")
or !aMajor->loadSound("Chords/A_major.wav")
or !a7->loadSound("Chords/A_7.wav")
or !aMajor7->loadSound("Chords/A_major7.wav")
or !cMajor->loadSound("Chords/C_major.wav")
or !dMajor->loadSound("Chords/D_major.wav")
or !dMinor->loadSound("Chords/D_minor.wav")
or !eMajor->loadSound("Chords/E_major.wav")
or !eMajor7->loadSound("Chords/E_major7.wav")
or !eMinor->loadSound("Chords/E_minor.wav")
or !eMinor7->loadSound("Chords/E_minor7.wav")
or !fMajor->loadSound("Chords/F_major.wav")
or !fMinor->loadSound("Chords/F_minor.wav")
or !gMajor->loadSound("Chords/G_major.wav")) {
printf("One or more sounds couldn't be loaded! %sn", Mix_GetError());
}
//Set chord names
aMinor->setChordName("A Minor", black, renderer, mediumFont);
aMajor->setChordName("A Major", black, renderer, mediumFont);
a7->setChordName("A7", black, renderer, mediumFont);
aMajor7->setChordName("A Major7", black, renderer, mediumFont);
cMajor->setChordName("C Major", black, renderer, mediumFont);
dMajor->setChordName("D Major", black, renderer, mediumFont);
dMinor->setChordName("D Minor", black, renderer, mediumFont);
eMajor->setChordName("E Major", black, renderer, mediumFont);
eMajor7->setChordName("E Major7", black, renderer, mediumFont);
eMinor->setChordName("E Minor", black, renderer, mediumFont);
eMinor7->setChordName("E Minor7", black, renderer, mediumFont);
fMajor->setChordName("F Major", black, renderer, mediumFont);
fMinor->setChordName("F Minor", black, renderer, mediumFont);
gMajor->setChordName("G Major", black, renderer, mediumFont);
This code is defined within the 'update' method
//Used to prevent this section running in the normal game loop
if (rounds == changeLevel) {
//Randomly choose sounds
randomSoundLeft = Sounds.at(rand() % Sounds.size());
randomSoundMiddle = Sounds.at(rand() % Sounds.size());
randomSoundRight = Sounds.at(rand() % Sounds.size());
//Create a new container and add the possible choices to the container
randomSounds.emplace_back(randomSoundLeft, randomSoundMiddle, randomSoundRight);
//Randomly chose one of the options to be the sound that the user plays
currentPlayingSound = randomSounds.at(rand() % randomSounds.size());
++changeLevel;
}
I expected the chords containing a name and a sound to be added to the vector without any issues. However, i have this error:
Error C2440 'initializing': cannot convert from 'initializer list' to '_Objty'
c++ visual-c++
|
show 3 more comments
I'm creating a program where the user has to identify certain chords. I'm using SDL to render text and shapes onto a GUI and SDL_Mixer to load sounds. The program will require the user to play a sound and guess the sound that was played using a series of options. The rest of the program works fine. However, the issue occurred once i tried to implement a way to load and work with sounds. All of the code below is encapsulated in a class.
I tried commenting out certain parts of the code and i found that the error occurs when i try to add the sounds to the vector using emplace_back(). The error occurs at line 881 of a file called xmemory0. This is the code where the error occurs "_Objty(_STD forward<_Types>(_Args)...);".
This code has it's access specifier defined as private
//Container to hold the sound data
std::vector<Sound*>Sounds;
//Container to hold the randomly selected sounds;
std::vector<Sound*> randomSounds;
Sound* aMinor{ new Sound{} };
Sound* aMajor{ new Sound{} };
Sound* a7{ new Sound{} };
Sound* aMajor7{ new Sound{} };
Sound* cMajor{ new Sound{} };
Sound* dMajor{ new Sound{} };
Sound* dMinor{ new Sound{} };
Sound* eMajor{ new Sound{} };
Sound* eMinor{ new Sound{} };
Sound* eMinor7{ new Sound{} };
Sound* eMajor7{ new Sound{} };
Sound* fMajor{ new Sound{} };
Sound* fMinor{ new Sound{} };
Sound* gMajor{ new Sound{} };
//These are the pointers for the randomly selected sounds
Sound* randomSoundLeft;
Sound* randomSoundMiddle;
Sound* randomSoundRight;
//Pointer for the sound which the user will play
Sound* currentPlayingSound;
This code is defined within a 'load data' method
//Add sounds to vector
Sounds.emplace_back(aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor);
//Load sounds
if (!aMinor->loadSound("Chords/A_minor.wav")
or !aMajor->loadSound("Chords/A_major.wav")
or !a7->loadSound("Chords/A_7.wav")
or !aMajor7->loadSound("Chords/A_major7.wav")
or !cMajor->loadSound("Chords/C_major.wav")
or !dMajor->loadSound("Chords/D_major.wav")
or !dMinor->loadSound("Chords/D_minor.wav")
or !eMajor->loadSound("Chords/E_major.wav")
or !eMajor7->loadSound("Chords/E_major7.wav")
or !eMinor->loadSound("Chords/E_minor.wav")
or !eMinor7->loadSound("Chords/E_minor7.wav")
or !fMajor->loadSound("Chords/F_major.wav")
or !fMinor->loadSound("Chords/F_minor.wav")
or !gMajor->loadSound("Chords/G_major.wav")) {
printf("One or more sounds couldn't be loaded! %sn", Mix_GetError());
}
//Set chord names
aMinor->setChordName("A Minor", black, renderer, mediumFont);
aMajor->setChordName("A Major", black, renderer, mediumFont);
a7->setChordName("A7", black, renderer, mediumFont);
aMajor7->setChordName("A Major7", black, renderer, mediumFont);
cMajor->setChordName("C Major", black, renderer, mediumFont);
dMajor->setChordName("D Major", black, renderer, mediumFont);
dMinor->setChordName("D Minor", black, renderer, mediumFont);
eMajor->setChordName("E Major", black, renderer, mediumFont);
eMajor7->setChordName("E Major7", black, renderer, mediumFont);
eMinor->setChordName("E Minor", black, renderer, mediumFont);
eMinor7->setChordName("E Minor7", black, renderer, mediumFont);
fMajor->setChordName("F Major", black, renderer, mediumFont);
fMinor->setChordName("F Minor", black, renderer, mediumFont);
gMajor->setChordName("G Major", black, renderer, mediumFont);
This code is defined within the 'update' method
//Used to prevent this section running in the normal game loop
if (rounds == changeLevel) {
//Randomly choose sounds
randomSoundLeft = Sounds.at(rand() % Sounds.size());
randomSoundMiddle = Sounds.at(rand() % Sounds.size());
randomSoundRight = Sounds.at(rand() % Sounds.size());
//Create a new container and add the possible choices to the container
randomSounds.emplace_back(randomSoundLeft, randomSoundMiddle, randomSoundRight);
//Randomly chose one of the options to be the sound that the user plays
currentPlayingSound = randomSounds.at(rand() % randomSounds.size());
++changeLevel;
}
I expected the chords containing a name and a sound to be added to the vector without any issues. However, i have this error:
Error C2440 'initializing': cannot convert from 'initializer list' to '_Objty'
c++ visual-c++
Sound* aMinor{ new Sound{} };
<-- I'm pretty sure none of these have to be pointers... (Sound* randomSoundLeft;
i would initialize this to nullptr just to be safe)
– Borgleader
Dec 30 '18 at 17:15
4
Why all the dynamic allocation?
– Lightness Races in Orbit
Dec 30 '18 at 17:16
And where do you get the error? On which of the lines you show? And can you please try to create a Minimal, Complete, and Verifiable example to show us, with a comment on the line that causes the error.
– Some programmer dude
Dec 30 '18 at 17:17
1
Why all the irrelevant code? Provide a Minimal, Complete, and Verifiable example as required here please.
– πάντα ῥεῖ
Dec 30 '18 at 17:18
1
@JesperJuhl --_Objty
is an internal name in the library implementation.
– Pete Becker
Dec 30 '18 at 17:51
|
show 3 more comments
I'm creating a program where the user has to identify certain chords. I'm using SDL to render text and shapes onto a GUI and SDL_Mixer to load sounds. The program will require the user to play a sound and guess the sound that was played using a series of options. The rest of the program works fine. However, the issue occurred once i tried to implement a way to load and work with sounds. All of the code below is encapsulated in a class.
I tried commenting out certain parts of the code and i found that the error occurs when i try to add the sounds to the vector using emplace_back(). The error occurs at line 881 of a file called xmemory0. This is the code where the error occurs "_Objty(_STD forward<_Types>(_Args)...);".
This code has it's access specifier defined as private
//Container to hold the sound data
std::vector<Sound*>Sounds;
//Container to hold the randomly selected sounds;
std::vector<Sound*> randomSounds;
Sound* aMinor{ new Sound{} };
Sound* aMajor{ new Sound{} };
Sound* a7{ new Sound{} };
Sound* aMajor7{ new Sound{} };
Sound* cMajor{ new Sound{} };
Sound* dMajor{ new Sound{} };
Sound* dMinor{ new Sound{} };
Sound* eMajor{ new Sound{} };
Sound* eMinor{ new Sound{} };
Sound* eMinor7{ new Sound{} };
Sound* eMajor7{ new Sound{} };
Sound* fMajor{ new Sound{} };
Sound* fMinor{ new Sound{} };
Sound* gMajor{ new Sound{} };
//These are the pointers for the randomly selected sounds
Sound* randomSoundLeft;
Sound* randomSoundMiddle;
Sound* randomSoundRight;
//Pointer for the sound which the user will play
Sound* currentPlayingSound;
This code is defined within a 'load data' method
//Add sounds to vector
Sounds.emplace_back(aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor);
//Load sounds
if (!aMinor->loadSound("Chords/A_minor.wav")
or !aMajor->loadSound("Chords/A_major.wav")
or !a7->loadSound("Chords/A_7.wav")
or !aMajor7->loadSound("Chords/A_major7.wav")
or !cMajor->loadSound("Chords/C_major.wav")
or !dMajor->loadSound("Chords/D_major.wav")
or !dMinor->loadSound("Chords/D_minor.wav")
or !eMajor->loadSound("Chords/E_major.wav")
or !eMajor7->loadSound("Chords/E_major7.wav")
or !eMinor->loadSound("Chords/E_minor.wav")
or !eMinor7->loadSound("Chords/E_minor7.wav")
or !fMajor->loadSound("Chords/F_major.wav")
or !fMinor->loadSound("Chords/F_minor.wav")
or !gMajor->loadSound("Chords/G_major.wav")) {
printf("One or more sounds couldn't be loaded! %sn", Mix_GetError());
}
//Set chord names
aMinor->setChordName("A Minor", black, renderer, mediumFont);
aMajor->setChordName("A Major", black, renderer, mediumFont);
a7->setChordName("A7", black, renderer, mediumFont);
aMajor7->setChordName("A Major7", black, renderer, mediumFont);
cMajor->setChordName("C Major", black, renderer, mediumFont);
dMajor->setChordName("D Major", black, renderer, mediumFont);
dMinor->setChordName("D Minor", black, renderer, mediumFont);
eMajor->setChordName("E Major", black, renderer, mediumFont);
eMajor7->setChordName("E Major7", black, renderer, mediumFont);
eMinor->setChordName("E Minor", black, renderer, mediumFont);
eMinor7->setChordName("E Minor7", black, renderer, mediumFont);
fMajor->setChordName("F Major", black, renderer, mediumFont);
fMinor->setChordName("F Minor", black, renderer, mediumFont);
gMajor->setChordName("G Major", black, renderer, mediumFont);
This code is defined within the 'update' method
//Used to prevent this section running in the normal game loop
if (rounds == changeLevel) {
//Randomly choose sounds
randomSoundLeft = Sounds.at(rand() % Sounds.size());
randomSoundMiddle = Sounds.at(rand() % Sounds.size());
randomSoundRight = Sounds.at(rand() % Sounds.size());
//Create a new container and add the possible choices to the container
randomSounds.emplace_back(randomSoundLeft, randomSoundMiddle, randomSoundRight);
//Randomly chose one of the options to be the sound that the user plays
currentPlayingSound = randomSounds.at(rand() % randomSounds.size());
++changeLevel;
}
I expected the chords containing a name and a sound to be added to the vector without any issues. However, i have this error:
Error C2440 'initializing': cannot convert from 'initializer list' to '_Objty'
c++ visual-c++
I'm creating a program where the user has to identify certain chords. I'm using SDL to render text and shapes onto a GUI and SDL_Mixer to load sounds. The program will require the user to play a sound and guess the sound that was played using a series of options. The rest of the program works fine. However, the issue occurred once i tried to implement a way to load and work with sounds. All of the code below is encapsulated in a class.
I tried commenting out certain parts of the code and i found that the error occurs when i try to add the sounds to the vector using emplace_back(). The error occurs at line 881 of a file called xmemory0. This is the code where the error occurs "_Objty(_STD forward<_Types>(_Args)...);".
This code has it's access specifier defined as private
//Container to hold the sound data
std::vector<Sound*>Sounds;
//Container to hold the randomly selected sounds;
std::vector<Sound*> randomSounds;
Sound* aMinor{ new Sound{} };
Sound* aMajor{ new Sound{} };
Sound* a7{ new Sound{} };
Sound* aMajor7{ new Sound{} };
Sound* cMajor{ new Sound{} };
Sound* dMajor{ new Sound{} };
Sound* dMinor{ new Sound{} };
Sound* eMajor{ new Sound{} };
Sound* eMinor{ new Sound{} };
Sound* eMinor7{ new Sound{} };
Sound* eMajor7{ new Sound{} };
Sound* fMajor{ new Sound{} };
Sound* fMinor{ new Sound{} };
Sound* gMajor{ new Sound{} };
//These are the pointers for the randomly selected sounds
Sound* randomSoundLeft;
Sound* randomSoundMiddle;
Sound* randomSoundRight;
//Pointer for the sound which the user will play
Sound* currentPlayingSound;
This code is defined within a 'load data' method
//Add sounds to vector
Sounds.emplace_back(aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor);
//Load sounds
if (!aMinor->loadSound("Chords/A_minor.wav")
or !aMajor->loadSound("Chords/A_major.wav")
or !a7->loadSound("Chords/A_7.wav")
or !aMajor7->loadSound("Chords/A_major7.wav")
or !cMajor->loadSound("Chords/C_major.wav")
or !dMajor->loadSound("Chords/D_major.wav")
or !dMinor->loadSound("Chords/D_minor.wav")
or !eMajor->loadSound("Chords/E_major.wav")
or !eMajor7->loadSound("Chords/E_major7.wav")
or !eMinor->loadSound("Chords/E_minor.wav")
or !eMinor7->loadSound("Chords/E_minor7.wav")
or !fMajor->loadSound("Chords/F_major.wav")
or !fMinor->loadSound("Chords/F_minor.wav")
or !gMajor->loadSound("Chords/G_major.wav")) {
printf("One or more sounds couldn't be loaded! %sn", Mix_GetError());
}
//Set chord names
aMinor->setChordName("A Minor", black, renderer, mediumFont);
aMajor->setChordName("A Major", black, renderer, mediumFont);
a7->setChordName("A7", black, renderer, mediumFont);
aMajor7->setChordName("A Major7", black, renderer, mediumFont);
cMajor->setChordName("C Major", black, renderer, mediumFont);
dMajor->setChordName("D Major", black, renderer, mediumFont);
dMinor->setChordName("D Minor", black, renderer, mediumFont);
eMajor->setChordName("E Major", black, renderer, mediumFont);
eMajor7->setChordName("E Major7", black, renderer, mediumFont);
eMinor->setChordName("E Minor", black, renderer, mediumFont);
eMinor7->setChordName("E Minor7", black, renderer, mediumFont);
fMajor->setChordName("F Major", black, renderer, mediumFont);
fMinor->setChordName("F Minor", black, renderer, mediumFont);
gMajor->setChordName("G Major", black, renderer, mediumFont);
This code is defined within the 'update' method
//Used to prevent this section running in the normal game loop
if (rounds == changeLevel) {
//Randomly choose sounds
randomSoundLeft = Sounds.at(rand() % Sounds.size());
randomSoundMiddle = Sounds.at(rand() % Sounds.size());
randomSoundRight = Sounds.at(rand() % Sounds.size());
//Create a new container and add the possible choices to the container
randomSounds.emplace_back(randomSoundLeft, randomSoundMiddle, randomSoundRight);
//Randomly chose one of the options to be the sound that the user plays
currentPlayingSound = randomSounds.at(rand() % randomSounds.size());
++changeLevel;
}
I expected the chords containing a name and a sound to be added to the vector without any issues. However, i have this error:
Error C2440 'initializing': cannot convert from 'initializer list' to '_Objty'
c++ visual-c++
c++ visual-c++
edited Dec 30 '18 at 17:22
Daniel
asked Dec 30 '18 at 17:12
DanielDaniel
285
285
Sound* aMinor{ new Sound{} };
<-- I'm pretty sure none of these have to be pointers... (Sound* randomSoundLeft;
i would initialize this to nullptr just to be safe)
– Borgleader
Dec 30 '18 at 17:15
4
Why all the dynamic allocation?
– Lightness Races in Orbit
Dec 30 '18 at 17:16
And where do you get the error? On which of the lines you show? And can you please try to create a Minimal, Complete, and Verifiable example to show us, with a comment on the line that causes the error.
– Some programmer dude
Dec 30 '18 at 17:17
1
Why all the irrelevant code? Provide a Minimal, Complete, and Verifiable example as required here please.
– πάντα ῥεῖ
Dec 30 '18 at 17:18
1
@JesperJuhl --_Objty
is an internal name in the library implementation.
– Pete Becker
Dec 30 '18 at 17:51
|
show 3 more comments
Sound* aMinor{ new Sound{} };
<-- I'm pretty sure none of these have to be pointers... (Sound* randomSoundLeft;
i would initialize this to nullptr just to be safe)
– Borgleader
Dec 30 '18 at 17:15
4
Why all the dynamic allocation?
– Lightness Races in Orbit
Dec 30 '18 at 17:16
And where do you get the error? On which of the lines you show? And can you please try to create a Minimal, Complete, and Verifiable example to show us, with a comment on the line that causes the error.
– Some programmer dude
Dec 30 '18 at 17:17
1
Why all the irrelevant code? Provide a Minimal, Complete, and Verifiable example as required here please.
– πάντα ῥεῖ
Dec 30 '18 at 17:18
1
@JesperJuhl --_Objty
is an internal name in the library implementation.
– Pete Becker
Dec 30 '18 at 17:51
Sound* aMinor{ new Sound{} };
<-- I'm pretty sure none of these have to be pointers... (Sound* randomSoundLeft;
i would initialize this to nullptr just to be safe)– Borgleader
Dec 30 '18 at 17:15
Sound* aMinor{ new Sound{} };
<-- I'm pretty sure none of these have to be pointers... (Sound* randomSoundLeft;
i would initialize this to nullptr just to be safe)– Borgleader
Dec 30 '18 at 17:15
4
4
Why all the dynamic allocation?
– Lightness Races in Orbit
Dec 30 '18 at 17:16
Why all the dynamic allocation?
– Lightness Races in Orbit
Dec 30 '18 at 17:16
And where do you get the error? On which of the lines you show? And can you please try to create a Minimal, Complete, and Verifiable example to show us, with a comment on the line that causes the error.
– Some programmer dude
Dec 30 '18 at 17:17
And where do you get the error? On which of the lines you show? And can you please try to create a Minimal, Complete, and Verifiable example to show us, with a comment on the line that causes the error.
– Some programmer dude
Dec 30 '18 at 17:17
1
1
Why all the irrelevant code? Provide a Minimal, Complete, and Verifiable example as required here please.
– πάντα ῥεῖ
Dec 30 '18 at 17:18
Why all the irrelevant code? Provide a Minimal, Complete, and Verifiable example as required here please.
– πάντα ῥεῖ
Dec 30 '18 at 17:18
1
1
@JesperJuhl --
_Objty
is an internal name in the library implementation.– Pete Becker
Dec 30 '18 at 17:51
@JesperJuhl --
_Objty
is an internal name in the library implementation.– Pete Becker
Dec 30 '18 at 17:51
|
show 3 more comments
1 Answer
1
active
oldest
votes
emplace_back method is to emplace one element. It takes arbirtary number of arguments as all of them are passed to constructor of a single element.
To add many elements at once you need to use method that accepts iterator range or initializer list.
This should work:
Sounds.insert(Sounds.end(), {aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor});
If your version of compiler does not support initializer lists, this would work:
Sound* inserted = {aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor};
Sounds.insert(Sounds.end(), inserted, inserted+sizeof(inserted)/sizeof(inserted[0]));
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979731%2fwhy-am-i-getting-a-initializing-cannot-convert-from-initializer-list-to%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
emplace_back method is to emplace one element. It takes arbirtary number of arguments as all of them are passed to constructor of a single element.
To add many elements at once you need to use method that accepts iterator range or initializer list.
This should work:
Sounds.insert(Sounds.end(), {aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor});
If your version of compiler does not support initializer lists, this would work:
Sound* inserted = {aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor};
Sounds.insert(Sounds.end(), inserted, inserted+sizeof(inserted)/sizeof(inserted[0]));
add a comment |
emplace_back method is to emplace one element. It takes arbirtary number of arguments as all of them are passed to constructor of a single element.
To add many elements at once you need to use method that accepts iterator range or initializer list.
This should work:
Sounds.insert(Sounds.end(), {aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor});
If your version of compiler does not support initializer lists, this would work:
Sound* inserted = {aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor};
Sounds.insert(Sounds.end(), inserted, inserted+sizeof(inserted)/sizeof(inserted[0]));
add a comment |
emplace_back method is to emplace one element. It takes arbirtary number of arguments as all of them are passed to constructor of a single element.
To add many elements at once you need to use method that accepts iterator range or initializer list.
This should work:
Sounds.insert(Sounds.end(), {aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor});
If your version of compiler does not support initializer lists, this would work:
Sound* inserted = {aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor};
Sounds.insert(Sounds.end(), inserted, inserted+sizeof(inserted)/sizeof(inserted[0]));
emplace_back method is to emplace one element. It takes arbirtary number of arguments as all of them are passed to constructor of a single element.
To add many elements at once you need to use method that accepts iterator range or initializer list.
This should work:
Sounds.insert(Sounds.end(), {aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor});
If your version of compiler does not support initializer lists, this would work:
Sound* inserted = {aMinor, aMajor, aMajor7,
a7,cMajor, dMajor, dMinor,
eMajor, eMajor7, eMinor, eMinor7,
fMajor, fMinor, gMajor};
Sounds.insert(Sounds.end(), inserted, inserted+sizeof(inserted)/sizeof(inserted[0]));
answered Jan 1 at 8:30
Alexander GutenevAlexander Gutenev
704710
704710
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979731%2fwhy-am-i-getting-a-initializing-cannot-convert-from-initializer-list-to%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Sound* aMinor{ new Sound{} };
<-- I'm pretty sure none of these have to be pointers... (Sound* randomSoundLeft;
i would initialize this to nullptr just to be safe)– Borgleader
Dec 30 '18 at 17:15
4
Why all the dynamic allocation?
– Lightness Races in Orbit
Dec 30 '18 at 17:16
And where do you get the error? On which of the lines you show? And can you please try to create a Minimal, Complete, and Verifiable example to show us, with a comment on the line that causes the error.
– Some programmer dude
Dec 30 '18 at 17:17
1
Why all the irrelevant code? Provide a Minimal, Complete, and Verifiable example as required here please.
– πάντα ῥεῖ
Dec 30 '18 at 17:18
1
@JesperJuhl --
_Objty
is an internal name in the library implementation.– Pete Becker
Dec 30 '18 at 17:51