0
我正在與多個類的CPP項目工作,並且我堅持了一段時間。我有顆粒類(頭文件):未知覆蓋說明符
#pragma once
#ifndef PARTICLE_H
#define PARTICLE_H
class Particle {
private:
vec3 pos; // <- here I get an error
vec3 dir;
float speed;
float size;
float amb[3];
public:
Particle();
Particle(bool sludge);
inline void setPosX(float posX);
inline void setPosY(float posY);
inline void setPosZ(float posZ);
inline void setSpeed(float speed);
inline void setSize(float size);
void setAmb(float amb0, float amb1, float amb2);
inline float getPosX();
inline float getPosY();
inline float getPosZ();
inline float getDirX();
inline float getDirY();
inline float getDirZ();
inline float getSpeed();
inline float getSize();
void renderParticle();
void renderSludge();
};
#endif
和CPP文件包括(爲簡單起見):
#include "stdafx.h"
#include "Tools.h"
#include "Particle.h"
#include "Player.h"
和工具類,它包含結構VEC 3:
#pragma once
#ifndef TOOLS_H
#define TOOLS_H
void distance(float posX1, float posY1, float posZ1, float radius1, float posX2, float posY2, float posZ2, float radius2);
int fibonacci(int num);
GLuint LoadObj(char * file);
GLuint LoadTexture(char * file, int magFilter, int minFilter);
void drawSphere(float r, int divisions);
void OnRender();
void OnReshape(int, int);
void OnKeyPress(unsigned char, int, int);
void OnKeyDown(unsigned char, int, int);
void OnKeyUp(unsigned char, int, int);
void OnTimer(int);
struct vec3 {
float x, y, z;
};
struct SFace {
int v[3];
int n[3];
int t[3];
};
#endif
我得到an:Error C3646 'pos': unknown override specifier
,我不明白爲什麼,因爲Tools.h
似乎只包含一次,而Particle類應該知道Tools包含vec3
。我試圖在Particle類的開頭宣佈struct vec3
,但它沒有工作,我也做了一些沒有任何效果的研究,所以我會感謝任何提示和幫助。
particle.h如何知道tools.h中的whats? – Eddge
你用C++ 11編譯嗎? 'override'關鍵字是C++ 11及更高版本的新手(儘管我沒有看到它在您提供的代碼中使用) – CoryKramer
您可能在「Particle.cpp」之外的文件中包含「Particle.h」。此時,可能不包括'Tools.h'。在'Particle.h'中包含你需要的頭文件。將頭部包含兩次是沒有問題的,特別是因爲它似乎被'#include'後衛和'#pragma Once'兩者所保護。 –