I want to create a method where I have a variable argument type. I'm writing a library that needs to have this because you can't be certain which type of object a user wants to use.
It's a method that serializes an object made with the Google ProtocolBuffer but the ProtocolBuffer object can be of different types (the name can change).
Is this possible? I tried with this but it doesn't work:
template <class X>
void Base::Send(X data)
{
// Serialize to string.
std::string sendData;
data.SerializeToString(&sendData);
// Convert data to const char*
const char* dataToSend = sendData.c_str();
int iResult;
iResult = send( ConnectSocket, dataToSend, (int)strlen(dataToSend), 0 );
if (iResult == SOCKET_ERROR)
{
printf("send failed with error: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
exit(1);
}
}