so I have this line of code that I'm using for files:
inCreditSystem.seekp((num - 1) * sizeof(client));
// And sometimes I have this code
inCreditSystem.seekp((num - 1) * sizeof(ClientData));
where
fstream inCreditSystem("credit.dat", ios::in | ios::out | ios::binary);
ClientData client;
On it's own, my code works but I wanted to show my skills to my teacher(since this is a final exercice for my term) so I wanted to place this in a template. (I have succesfully placed write and read for files in a template)
//In FileFunctions class, I have these lines of code
template <class T> ostream& binary_seekp(ostream&, T&, int);
template <class T> ostream& binary_seekp2(ostream&, T&, int);
//And this is the rest of the code
template<class T>
ostream& FileFunctions::binary_seekp(ostream& stream, T& value, int num)
{
return stream.seekp((num-1) * sizeof(value));
}
template<class T>
ostream& FileFunctions::binary_seekp2(ostream& stream, T& value, int num)
{
return stream.seekp((num-1) * sizeof(T));
}
and then call the function like this
binary_seekp(inCreditSystem, client, num);
binary_seekp2(inCreditSystem, client, num);
I have two templates for seek because as you can see, one line of code gets the size of 'ClientData' and the other gets the size of 'Client'.
Keep in mind FileFunctions is another class. When I run this code and finalize a record, it wont show up when I print them but they will if I do it with that one line of code. Any clue why my code won't work?