My history with programming is in C and CPython. Please bear with me here.
To help me learn C++ I am converting one of my old C programs to use C++ OOP, but it's not working the way I want it to work. I don't care about speed. I just care about learning.
Here's my old C code I want to put into a Checksum class:
//This is the standard CRC32 implementation
//"rollingChecksum" is used so the caller can maintain the current
//checksum between function calls
unsigned int CalculateChecksum(unsigned char* eachBlock, int* sbox, long lengthOfBlock, unsigned int rollingChecksum)
{
int IndexLookup;
int blockPos;
for(blockPos = 0; blockPos < lengthOfBlock; blockPos++)
{
IndexLookup = (rollingChecksum >> 0x18) ^ eachBlock[blockPos];
rollingChecksum = (rollingChecksum << 0x08) ^ sbox[IndexLookup];
}
return rollingChecksum;
}
So here's how I translated it into more C++'ey code:
void Checksum::UpdateStream(std::vector<unsigned char> binaryData)
{
unsigned int indexLookup;
unsigned int blockPos;
for(blockPos = 0; blockPos < binaryData.size(); blockPos++)
{
indexLookup = (this->checksum >> 0x18) ^ binaryData[blockPos];
this->checksum = (this->checksum << 0x08) ^ this->sbox[indexLookup];
}
}
But then when I try to use it:
int main(int argc, char* argv[])
{
Checksum Test;
Test.UpdateStream("foo bar foobar");
std::cout << Test.getChecksum() << std::endl;
}
I get this error:
1>main.cpp(7) : error C2664: 'Checksum::UpdateStream' : cannot convert parameter 1 from 'const char [15]' to 'std::vector<_Ty>'
1> with
1> [
1> _Ty=unsigned char
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
I decided to use the vector container above instead of the string class because of how this question turned out on StackOverflow and because I want to use binary data here.
DESIRED RESULT: How can I pass both strings and binary data to this method to calculate its checksum? Do I need to overload it or typecast the string in main? I'm completely lost.