mardi 1 août 2017

How to handle an api which returns different data types for the same input data types?

How to handle an api which returns different data types for the same input data types?

Looking at the below example, apicall should return a date or a string depending on the input attribute:

#include <iostream>
#include <string>

using namespace std;

???? apicall(string datatype, string attribute)
{
    // code
}

int main(int argc, char** argv)
{
    string datatype = "Thomas"
    string attribute = "bithday"
    cout << apicall(datatype, attribute) << endl;

    string datatype = "Thomas"
    string attribute = "address"
    cout << apicall(datatype, attribute) << endl;
}

What could be in place of ???? (apicall return datatype) and how to handle these cases?

I am trying to understand these concepts as my experience to date has been with duck typed scripting languages.

Aucun commentaire:

Enregistrer un commentaire