无法识别的类型 - “错误:变量”[var-name]不是类型名称' [英] Unrecognised type - 'Error: Variable "[var-name]" is not a type name'
问题描述
我正在创建一个类来处理物理作为项目的一部分。我们被告知要使用一个处理任意行为的类。
I'm creating a class for handling physics as part of a project. We were told to use a class which handles arbitrary behaviours.
我创建了一个类,它将根据给定的模块更新内部状态(代码如下)。然而,表示内部状态 PhysicsData
的结构在除了它自己的文件之外不被识别。任何人都可以散发一些光?
I've created a class which will update an internal state based on modules that are given to it (code follows). However, the structure representing the internal state, PhysicsData
, isn't being recognised anywhere except its own file. Can anyone shed some light?
(对不起,大量的信息,但对象之间的差距是一个问题和地方是一个问题是相当大,修剪额外的细节也删除了有用的上下文)
(Sorry for the massive dump of information, but the gap between the object being a problem and the place where it's a problem is quite large and trimming down the extra details also removes context that can be useful)
这里是有问题的结构:
#pragma once
// This file "PhysicsBehaviourBase.h"
#include <d3dx9.h>
#include <vector>
struct PhysicsData
{
public:
D3DXVECTOR3 velocity;
D3DXVECTOR3 position;
D3DXVECTOR3 rotation;
float size;
PhysicsData();
void add(const PhysicsData& pd);
};
所有对 PhysicsData
这个文件很好。但是这个文件开始提示问题:
All references to PhysicsData
in the rest of this file are fine. However this file starts to hint at problems:
#pragma once
// This file: "PhysicsBehaviours.h"
#include "PhysicsBehavioursBase.h"
class GravityConstant : public PhysicsBehaviour
{
private:
float g; // Gravitational constant
// Required by the PhysicsBehaviour interface.
PhysicsBehaviour* copy() const {return new GravityConstant(g);}
public:
GravityConstant(float accelleration_due_to_gravity = 9.81)
: g(accelleration_due_to_gravity) {}
// Required by the PhysicsBehaviour interface.
void update(float time,const PhysicsData&, PhysicsData* out)
{out->velocity.y -= g*time;}
};
在 void update(float time,const PhysicsData& PhysicsData * out )
行对 PhysicsData
的引用都给出了IntelliSense错误消息:
In the void update(float time,const PhysicsData&, PhysicsData* out)
line both references to PhysicsData
are given the IntelliSense error message:
Physics PhysicsData
Error: variable "PhysicsData" is not a type name.
我不知道为什么IntelliSense认为 PhysicsData
是 Physics
类型的变量。 ( Physics
是我声明的类型, PhysicsData
是用于构造物理对象的参数之一)。
I have no idea why IntelliSense think PhysicsData
is a variable of type Physics
. (Physics
is a type I declare next, and PhysicsData
is one of the parameters used to construct a physics object).
但是,此时没有编译器错误。编译器错误发生在层次结构中的下一个文件中:
There is no compiler error at this point, however. The compiler error happens in the next file up the hierarchy:
#pragma once
// "Physics.h"
#include "Timing.h"
#include "PhysicsBehaviours.h"
#include <d3dx9.h> // For D3DXVECTOR3
#include <vector>
class Physics
{
private:
std::vector<PhysicsBehaviour*> behaviours_;
Timing timer;
PhysicsData data;
void addBehaviours(const BEHAVIOUR_LIST&);
public:
Physics(const PhysicsData&,const BEHAVIOUR_LIST&);
~Physics() {}
void update();
PhysicsData state() const {return data;}
float age() const {return timer.age();}
};
这两个对PhysicsData的引用获得与上述相同的IntelliSense错误。编译器错误指向此函数:
Both references to PhysicsData get the same IntelliSense error as above. Compiler errors point to this function:
#include "Physics.h"
// "Physics.cpp"
Physics(const PhysicsData& initalState,const BEHAVIOUR_LIST& behaviour) // Line 4
: data(initialState) // Line 5
{ // Line 6
addBehaviours(behaviour);
}
编译器错误:
1> Physics.cpp
1>[PATH]\physics.cpp(4): error C2226: syntax error : unexpected type 'PhysicsData'
1>[PATH]\physics.cpp(5): error C2065: 'initialState' : undeclared identifier
1>[PATH]\physics.cpp(6): error C2448: 'data' : function-style initializer appears to be a function definition
更多IntelliSense错误:
在&
const PhysicsData&
来自第4行:
And more IntelliSense errors:
Underneath the &
in const PhysicsData&
from line 4:
Error: this declaration has no storage class or type specifier.
第4行的小括号下:
Error: expected a declaration.
欢迎任何线索,修正或假设。
Any clues, fixes or hypotheses are welcome.
推荐答案
您缺少来自 Physics.cpp $ c中构造函数定义的类说明符$ c>:
Physics::Physics(const PhysicsData& initalState,const BEHAVIOUR_LIST& behaviour)
^^^^^^^^^
这篇关于无法识别的类型 - “错误:变量”[var-name]不是类型名称'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!