Указатель на функцию C ++ шаблонного типа - PullRequest
0 голосов
/ 09 мая 2020

Это, вероятно, самый сложный фрагмент кода шаблона, который я написал.

У меня есть следующие типы, объявленные с шаблонами:

    template <class Vertex, class Pixel>
    using VS_TYPE = Pixel(*)(Vertex & v);

    template <class Vertex, class Pixel, class Mesh>
    using VS_THIS_TYPE = Pixel(Mesh::*)(Vertex & v);

    template <class Pixel>
    using PS_TYPE = Vec4(*)(Pixel & sd, const Sampler<Pixel> & sampler);

    template <class Pixel, class Mesh>
    using PS_THIS_TYPE = Vec4(Mesh::*)(Pixel & sd, const Sampler<Pixel> & sampler);

Это типы указателей на функции с шаблонами параметры и возвращаемые значения. Те, что с «ЭТОМ», являются указателями на функции-члены (класса Me sh). Я объявил эту шаблонную функцию, которая принимает некоторые параметры этих типов:

template <class Vertex, class Pixel, class Mesh>
    void DrawElementArray(Mesh* mesh, Vertex* vertices, VS_THIS_TYPE<Vertex, Pixel, Mesh> VertexShader, PS_THIS_TYPE<Pixel, Mesh> PixelShader)
{
      // body of this function
      boundObject = (void*)mesh;
      _DrawElementArray<Vertex, Pixel, Mesh, VS_THIS_TYPE<Vertex, Pixel, Mesh>, PS_THIS_TYPE<Pixel, Mesh>>(..., VertexShader, PixelShader);
}

Параметры VertexShader и PixelShader относятся к этим типам указателей шаблонных функций. Вот объявление функции _DrawElementArray:

template <class Vertex, class Pixel, class Mesh, typename VSPtr, typename PSPtr>
    void _DrawElementArray(Vertex* vertices, VSPtr VertexShader, PSPtr PixelShader)
{
     // bound object is the Mesh* parameter passed into DrawElementArray
     // There is another DrawElementArray not shown that does not have this parameter, used for passing in Vertex
    // Shader and PixelShader function pointers that are not member functions
     //
     if (boundObject == nullptr) {

           // call vertex shader (parameter unrelated)
           VertexShader(vertices[i3])
     } else {

           // call the member function on the object
           Mesh* mesh = (Mesh*)boundObject;
           (mesh->*VertexShader)(vertices[i1])
     }
}

Проблема возникает, когда я пытаюсь вызвать VertexShader (параметр указателя функции). Это дает следующие ошибки:

    term does not evaluate to a function taking 1 arguments
    ->* : illegal right operand has type VSPtr

Я могу вызвать DrawElementArray, не увидев ошибок компиляции. Кто-нибудь знает, как исправить эти ошибки? По сути, я пытаюсь написать функцию (_DrawElementArray), которая могла бы принимать указатели функций либо на функции-члены, либо на функции, не являющиеся членами

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...