mercredi 17 avril 2019

How to pass a typedef array of a struct into a templated function for any type?

Running into a confusing issue here using C++11 with the MSVC 17 32-bit Visual Studio compiler. I have these functions:

template <typename type>
void anotherThing(type &t)
{
   ...
}
template <typename type>
void doThing(type t)
{
   anotherThing(t)
}

And I want to call the function doThing for a variety of types including the one that is giving me trouble which is myType:

typedef struct
{
   int a;
   int b;
} subtype;

typedef subtype myType[512];

Error I'm getting is cannot convert argument from myType(*) to type(&) when calling the function like this:

myType A;
doThing<myType>(A);

I don't have control over how subtype and myType are written, but I have full control over my functions. Can I solve this issue without changing my function signatures? Thanks!

Aucun commentaire:

Enregistrer un commentaire