可能的转发声明错误
Possible forward declaration error
我有两个文件。一个是main.cpp它 #includes"MouseController.h",它有一个鼠标对象的classdef。如果 MouseController.h 没有导入或包含,为什么 main 在查找我的鼠标类时遇到问题?
如果它有任何用途,Xcode 的 CMD 单击允许您将某些内容追溯到其声明,它会发现 Mouse 类正常。
主.cpp
#include <GLUT/GLUT.h>
#include <OpenGL/OpenGL.h>
#include <iostream>
#import "MouseController.h"
Mouse mouse;
float angle = 0.0f;
void selfInit();
void glInit();
void DisplayCallback();
void ReshapeCallback(int w, int h);
void UpdateAll(int value);
int main(int argc, char** argv)
{
selfInit();
glutInit(&argc, argv);
glInit();
return 0;
}
此处之后不再引用鼠标对象。
鼠标控制器.h
#ifndef __FinalPiece__MouseController__
#define __FinalPiece__MouseController__
class Mouse {
public:
static int CurrentX;
static int CurrentY;
static int LastX;
static int LastY;
static int DeltaX;
static int DeltaY;
static void move(int x, int y);
static void update();
static void clicked(int button, int state, int x, int y);
};
#endif
没有看到你的代码,这是一个黑暗中的镜头,但听起来你遇到了链接器错误。
// main.cpp
#include "MouseController.h"
int main()
{
// do stuff
return 0;
}
// MouseController.cpp
#include "MouseController.h"
// implement MouseController here
// MouseController.h
// define MouseController here
如果 MouseController.cpp 不存在,未被编译(即不是项目或 Makefile 的一部分),或者 MouseController.h 没有内联实现类,编译器知道 MouseController 应该是什么样子,但链接器找不到它。
相关文章:
- 在气泡排序程序中未声明错误功能
- 未在此范围内声明错误 'xy'
- 在此范围内未声明错误"Clreol"
- 为什么 C 编译器不在 for 循环体中给出重新声明错误?
- 如何修复范围内的字符串声明错误
- 如何修复C++中的"arrStud未在此范围内声明"错误
- 无法识别的模板声明错误 - 不明白我做错了什么
- C 如何从构造函数中声明(错误C2065未宣布的标识符)
- C 无法解释的类“尚未声明”错误,这是由于名称空间而导致的
- 如何解决声明错误
- 在标题文件中获取声明错误
- 异常声明错误
- "inet_ntoa"未声明错误
- #include <string> 导致很多'<blank>'尚未声明错误
- 类声明错误
- C++成员函数未声明错误时(当它看起来是错误时)
- 代码块 HelloWorld C 示例不起作用:未声明错误"ptrdiff_t"
- 头文件类成员函数声明错误:"incomplete type name in nested name specifier"
- 预期语句和预期声明错误 c++
- 针对 android 编译的问题..."未在此范围内声明"错误