vectors of structs
Hey I'm pretty new to C++ but have quite a bit of experience in Java. I have a project to make a Morse code translator. I have a struct that holds a letter and its morse code equivalent. Then I have a vector of these structs to hold all of the combinations. Here's the code thats giving me problems.
cerr << "Cannot open: " << myConversionTableFile << "." << endl;
for(int i = 0; i < myConvertorTable->size(); i++)
cout << "morse: " << myConvertorTable->morse->at(i) << endl;
cout << "letter: " << myConvertorTable->letter->at(i) << endl;
Heres the error messages.
MorseCodeTranslator.cpp: In member function ‚void MorseCodeTranslator::setupConvertorTable()‚:
MorseCodeTranslator.cpp:19: error: ‚class std::vector<MorseCodeTranslator::Code, std::allocator<MorseCodeTranslator::Code> >‚ has no member named ‚letter‚
MorseCodeTranslator.cpp:22: error: ‚class std::vector<MorseCodeTranslator::Code, std::allocator<MorseCodeTranslator::Code> >‚ has no member named ‚morse‚
The error messages mean exactly what they say: vector<Code> does not, in fact, contain any letters, or any morses. It contains Codes. You need to build a Code and push_back that. You can use a tempCode, just like you're using a templetter and a tempmorse.
You've got it backwards. Should be:
Thanks the temp struct idea worked.
Ignore ME sorry I figured it out.
And don't forget to allocate memory for your vector (and free it), since it's a pointer!
But does it really [i]need[I] to be a pointer?