You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Camera未定义报错排查:已定义仍提示myCamera未定义等问题

Let's break down your issues one by one—there are a few straightforward mistakes in your code that are causing these errors:

1. Circular Header Inclusion in level.h

In your level.h file, you've included the file itself with #include "level.h". This creates a circular inclusion loop that confuses the compiler and prevents it from properly parsing your class definitions. Delete this line immediately.

2. Mismatched Constructor Name vs. Class Name

Your class is named Scene, but you declared its constructor as level(Input *in);—this is a critical mismatch! The .cpp file's level::level definition can't find a corresponding class, which is why the compiler doesn't recognize myCamera (it doesn't know which class that member belongs to).

  • Fix the constructor declaration in level.h to match the class name:
    Scene(Input *in);
    
  • Update the constructor definition in level.cpp to match:
    Scene::Scene(Input *in) {
        // Your existing code here
    }
    

3. Case Sensitivity Issue with the Camera Class

The error "Camera是未知覆盖说明符" (Camera is an unknown override specifier) almost certainly comes from a case mismatch between your class declaration and usage:

  • If your camera.h defines a class named Camera (uppercase C), you need to declare your member variable as Camera myCamera; (not lowercase camera myCamera;) in the Scene class.
  • Double-check camera.h to confirm the exact class name spelling and case—C++ is case-sensitive, so Camera and camera are treated as completely different types.

4. Incorrect Access to the Camera Instance

In your .cpp constructor, you wrote camera.position.x = 0;—this tries to access a static member of the camera class, but position is a member of your myCamera instance. Fix this to:

myCamera.position.x = 0;

5. Uninitialized width/height Variables

You're using width and height in gluPerspective before initializing them. This will cause invalid perspective matrix calculations. Add initial values in the constructor, e.g.:

width = 800; // Or pass these values in via the constructor
height = 600;

After fixing all these issues, clean your build directory and recompile—both of your errors should be resolved.

内容的提问来源于stack exchange,提问作者memelord420360

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:54:03