I am getting a very strange compile error pointing to where I declare a pointer to my class.
MyClass* myClass; //Line 34
Error:
MyFile.h|34|error: ISO C++ forbids declaration of ‘MyClass’ with no type
MyFilee.h|34|error: expected ‘;’ before ‘*’ token
I could not get a clue what is going wrong. Could anyone throw some light.
Seems to be declaration of MyClass is not visible at that point. Compiler considers MyClass as a new variable's name without type specified.
Related
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?
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.
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);
}
Seems like it never happened to anyone so I guess I'm doing something wrong...
The error I get is:
error: expected ';' at end of member declaration
error: 'noexcept' does not name a type
the code is this:
void* operator new (size_t size) noexcept
{return foo(size);}
also the code is in macro actually, if it matters.
Thanks!
I'm having problem passing member function pointers to templatized member function on gcc. Does anyone know how to modify the code below to get gcc to accept what I am trying to do?
class Foo
{
public:
template <class C, class R>
void Execute(R(typename C::*memFn)())
{
}
};
I get the following errors when trying to compile the code:
test.cpp:40: error: 'memFn' was not declared in this scope
test.cpp:40: error: expected primary-expression before '(' token
test.cpp:40: error: expected identifier before '*' token
test.cpp:40: error: expected '(' before '*' token
test.cpp:40: error: 'memFn' was not declared in this scope
test.cpp:40: error: variable or field 'Execute' declared void
The version of gcc that I am using is 4.4.2.
Thank you very much for your help!
You don't need typename. Remove that and it should work. (I tested it on gcc 4.3.2).
Error while writing static function.
static int function_name ( const Reference< data_type>* ptr)
{
}
when i wrote a static functin which takes Reference pointer then ir gives me following error
error: ISO C++ forbids declaration of 'Reference' with no type
error: expected ',' or '...' before '<' token
The compiler is complaining because it doesn't know what a Reference<T> is. Either you've forgotten to #include the header file that it is defined in, or you've forgotten to forward-declare it.
You presumably mean Reference to be a template but the compiler doesn't see it as one.
I have the following member data
vector<State<T>*> activeChildren;
I want to clean-up these pointers in my destructor
StateContainer<T>::~StateContainer() {
vector<State<T>*>::iterator it =
activeChildren.begin();
while(it!=activeChildren.end()) {
State<T>* ptr = *it;
it = activeChildren.erase(it);
delete ptr;
}
}
I get the following error from g++ 4.3.2 on Ubuntu:
./fsm2/StateContainer.cpp: In destructor ‘virtual ervan::StateContainer<T>::~StateContainer()’:
../fsm2/StateContainer.cpp:24: error: expected `;' before ‘it’
../fsm2/StateContainer.cpp:25: error: ‘it’ was not declared in this scope
Can anyone tell me what I've done wrong? I get this error in two more places where I use iterator loops, but not when I use for_each(...)
Looks like typename time again - I think you need:
typename vector<State<T>*>::iterator it = ...
A heuristic for g++ users - when you see this message in template code:
expected `;' before ‘it’
it is a pretty good bet that the thing in front of the 'it' is not being seen by the compiler as a type and so needs a 'typename' added.
It's a parsing issue. In this code, vector<State<T>*>::iterator is a nested dependent type.
Until you know what T is (and T isn't known at parse time), the parser/compiler doesn't realize that iterator is a type (could be a static member variable, for all it knows).
Therefore, you must prefix the definition with typename as a hint to tell the compiler that for all vector<State<T>*>, vector<State<T>*>::iterator is a type name.