C++ beginner's coding mistake: “Undeclared identifier”?

前端 未结 3 1896
予麋鹿
予麋鹿 2021-01-21 08:44

I\'m to use C++ for a very small part of my project. I must be coding something wrong, but my knowledge of C++ is what it is and I can\'t get around this...

See both the

相关标签:
3条回答
  • 2021-01-21 08:50

    void AbstractContactListener::isFixtureCollidingWithFixtureOfType(b2Fixture fix, int type)

    In the implementation.

    :)

    0 讨论(0)
  • 2021-01-21 08:55

    You forgot the class name from

    void isFixtureCollidingWithFixtureOfType(b2Fixture fix, int type)
    
    0 讨论(0)
  • 2021-01-21 09:01

    You forget to add the scope of the function. Try:

    void AbstractContactListener::isFixtureCollidingWithFixtureOfType(b2Fixture fix, int type){
    

    Why is the error pointing you to that strange place? The compiler sees your function definition and thinks that this is a free function, as there is nothing that indicates otherwise and tries to handle it as such. It fails, because it tries to find the variable in the global scope. This can get even funnier (read: more confusing): Image that this function does not use a class member. It will be simply parsed and compiled as a free function. As soon as your try to call it on an object of that type you will get a linker error.

    Also, I cannot see a declaration of the type id which is used in AbstractContactListener but that might just be because the code sample is incomplete.

    0 讨论(0)
提交回复
热议问题