爲了避免包含圓圈,我已將之前在類頭中的#include替換爲它的cpp文件。然後,我將一個前向聲明放入標題中。#include confusion
這解決了我的問題,但是,源文件似乎不再能夠訪問cpp文件中包含的文件的成員。爲什麼是這樣?什麼是解決方案?
編輯 - 下面真實代碼:
頭:
#ifndef BULLET_H
#define BULLET_H
#include "BoundingSphere.h"
#include "helperMethods.h"
class GameObject;
class Bullet : public GameObject
{
private:
float velocity;
float distance;
D3DXVECTOR3 firedFrom;
BoundingSphere bSphere;
public:
Bullet(D3DXVECTOR3 position, D3DXVECTOR3 rotation, float velocity, D3DXCOLOR colour);
BoundingSphere BulletSphere();//change this to simply use position
void Update();
};
#endif
源:
#include "Bullet.h"
#include "GameObject.h"
Bullet::Bullet(D3DXVECTOR3 position, D3DXVECTOR3 rotation, float velocity, D3DXCOLOR colour)
: bSphere(BoundingSphere(position, 0.01f))
{
//Model = content.Load<Model>("Models\\basicMesh");
//Texture = content.Load<Texture2D>("Textures\\basicMesh");
distance = 0.0f;
Scale(D3DXVECTOR3(0.25f, 0.1f, 0.1f));// error
Colour(colour); //error
firedFrom = position;
Rotation() = rotation; // error
this->velocity = velocity;
}
BoundingSphere Bullet::BulletSphere()
{
return bSphere;
}
void Bullet::Update()
{
Position(D3DXVECTOR3Helper.PointOnXYCircle(firedFrom, distance, Rotation().z)); //error
bSphere.Centre(Position());
distance += velocity;
}
第一個錯誤是遊戲物體:基類未定義。
所有後續的錯誤是「錯誤:標識符‘無所謂’是不確定他們是公衆和遊戲對象的所有干將
構造函數不需要返回類型。但是,發佈的代碼不能編譯。 – themel
@themel正確,只是foo通常用於函數名。我的壞:) –
我改變了問題,所以它現在有實際的代碼 – SirYakalot