1

I searched this question, but am unable to figure out how to resolve this:

class DtEffect;
template <typename VertexFormat> 
class DtEffectRenderer : public DtFormatRenderer<VertexFormat>
{
public:

template <typename MemberType>
static DtEffect::VertexAttribPtrInfo VertexAttrib(const MemberType VertexFormat::* member)
{
    return DtEffect::VertexAttribPtrInfo(
        reinterpret_cast<const GLvoid*>(offsetof(VertexFormat, *member))
        , DtAttributeType<MemberType>::value
        , DtAttributeType<MemberType>::size);
}

protected:
   DtEffect* myEffect;
};

Error messages:

../../include/vrvGraphics/DtEffectRenderer.h: In static member function ‘static makVrv::DtEffect::VertexAttribPtrInfo makVrv::DtEffectRenderer<VertexFormat>::VertexAttrib(const MemberType VertexFormat::*)’:
../../include/vrvGraphics/DtEffectRenderer.h:115: error: expected primary-expression before ‘(’ token
../../include/vrvGraphics/DtEffectRenderer.h:116: error: expected unqualified-id before ‘*’ token
../../include/vrvGraphics/DtEffectRenderer.h:116: error: expected ‘)’ before ‘*’ token

Any ideas?

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
psquare
  • 79
  • 5
  • `VertexFormat::*`? – erip Apr 26 '16 at 14:29
  • Its usage is like so: myEffect->setVertexAttribPointers( sizeof(DtLineVertex), VertexAttrib(&DtLineVertex::position), VertexAttrib(&DtLineVertex::color), VertexAttrib(&DtLineVertex::offset), VertexAttrib(&DtLineVertex::directionAndLength) ); – psquare Apr 26 '16 at 14:31
  • 1
    Please provide a [mcve]. – Barry Apr 26 '16 at 14:32
  • post more code please. if member is supposed to be a function pointer than lookup how to phrase a proper function pointer type. – Uri Brecher Apr 26 '16 at 14:36

2 Answers2

6

It appears that you are trying to use offsetof macro to get an offset to a member identified through a pointer-to-member:

offsetof(VertexFormat, *member)

This is not going to work, because the second parameter of the offsetof macro must be member's name, not any kind of an expression that could be used to access the member. Compile error is decidedly cryptic, but there is little the compiler could do, because offsetof is a macro.

See 0xbadf00d's answer to this Q&A for information on finding member offset using pointer-to-member. His approach closely replicates the inner workings of the offsetof macro, but he uses a pointer to member instead of member's name.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
0

Looks like you have a missing '(' after VertexAttribPtrInfo. I added it back in below, try that to see if it works.

template <typename MemberType>
static DtEffect::VertexAttribPtrInfo VertexAttrib(const MemberType VertexFormat::* member)
{
return DtEffect::VertexAttribPtrInfo((
    reinterpret_cast<const GLvoid*>(offsetof(VertexFormat, *member))
    , DtAttributeType<MemberType>::value
    , DtAttributeType<MemberType>::size);
}