“(”标记之前出现意外的主表达式
Unexpected primary-expression before ‘(’ token
我搜索了这个问题,但无法弄清楚如何解决这个问题:
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;
};
错误消息:
../../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
有什么想法吗?
您似乎正在尝试使用offsetof
宏来获取通过指向成员的指针标识的成员的偏移量:
offsetof(VertexFormat, *member)
这是行不通的,因为offsetof
宏的第二个参数必须是成员的名称,而不是可用于访问成员的任何类型的表达式。编译错误显然是神秘的,但编译器几乎无能为力,因为offsetof
是一个宏。
有关使用指向成员的指针查找成员偏移量的信息,请参阅 0xbadf00d 对此问答的回答。他的方法密切复制了offsetof
宏的内部工作原理,但他使用指向成员的指针而不是成员的名称。
看起来你在VertexAttribPtrInfo之后缺少一个'('。我在下面重新添加了它,尝试一下看看它是否有效。
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);
}
相关文章:
- (C++)分析树以计算返回错误值的简单算术表达式
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 提升精神:解析布尔表达式并简化为规范范式
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 在C++中对T*类型执行std::move的意外行为
- 使用正则表达式regex_search在字符串中查找字符串
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- 概念中的cv限定符需要表达式参数列表
- 为什么constexpr的性能比正常表达式差
- 对于结构,表达式必须是可修改的ivalue
- C++ 编译错误:意外的类型名称"字符串":预期的表达式
- 使用 boost::regex 从目录中获取带有一些正则表达式的文件名称时出现意外输出
- MSVC:意外的标记"__cdecl",预期的"表达式"
- “(”标记之前出现意外的主表达式
- 正则表达式匹配产生意外结果
- 意外的DO-WHILE行为:它是否忽略了表达式
- Mex运行时错误:意外的标准表达式
- 在 CodeBlocks C++ 中发现的">"标记之前的意外主表达式
- c++ std:: string.Find以布尔表达式返回意外结果