我确保没有循环依赖,并且包含头文件以期让编译器理解所有内容但我错了
Edit1:还有像pragma一样的标题保护
编辑2:忘记添加所有头文件
我应该更专注于提供清晰完整的内容
相关文件:
Spawner.hpp //定义类
的头文件#pragma once
// code skipped
#include "weapon.hpp"
#include "movement.hpp"
class Spawner{
private:
int spawnGapTime;
int spawnGapSet;
// If you plan to spawn finite enemies, then use constructor
int spawnLimit = -1;
EnemyTemplate* enemyData;
Weapon* givenWeapon;
Movement* givenMovement;
int ticks;
public:
Spawner(Weapon*, Movement*, EnemyTemplate*, std::vector <int>);
void update();
void spawn_enemy();
void spawn_count();
~Spawner(){
delete givenWeapon;
delete givenMovement;
delete enemyData;
};
};
SceneGame.hpp(一些相关代码)
#pragma once
#include <SFML\Graphics.hpp>
#include "scene.hpp"
#include "game.hpp"
#include "entity.hpp"
#include "movement.hpp"
#include "weapon.hpp"
#include "player.hpp"
#include "collisionGrid.hpp"
#include "spawner.hpp"
// forward declare
class BulletTemplate;
class SceneGame : public Scene{
private:
// some code skipped
std::vector <Spawner*> spawner_list; // the source of the problem
// more code skipped
};
SceneGame.cpp(仅包含相关的构造函数)
#include "sceneGame.hpp"
#include "input.hpp"
SceneGame::SceneGame(Game* game){
this->game = game; // need this to run the game.
// code skipped
// SKIP to spawner_list
//
std::vector<BulletTemplate*> player_weapon;
// Typical 3-way gun
player_weapon.push_back(new BulletTemplate("bulletPlayer", 1, 15, false, 0));
player_weapon.push_back(new BulletTemplate("bulletPlayer", 1, 15, false, -15));
player_weapon.push_back(new BulletTemplate("bulletPlayer", 1, 15, false, 15));
// simple rapid fire
bullet_Patterns.push_back(player_weapon);
std::vector<BulletTemplate*> enemy_weapon;
// 2 shot rapid
enemy_weapon.push_back(new BulletTemplate("bulletEnemy", 1, 10, false, -5));
enemy_weapon.push_back(new BulletTemplate("bulletEnemy", 1, 10, false, 5));
bullet_Patterns.push_back(enemy_weapon);
// initalize Movement
std::vector<sf::Vector2f> waypoints = {
sf::Vector2f(-100, 0),
sf::Vector2f(-100, -100),
sf::Vector2f(0, -100),
};
//Movement* enemy_movement = new Movement(sf::Vector2f(400, 400), waypoints);
//
//
///*
std::vector <int> spawnParams = { 60 };
// This is where I use the variable that compiler complained
// Initalize the spawner
spawner_list.push_back(new Spawner(
new Weapon(enemy_weapon, "sequence_enemy", 60, { 8 }),
new Movement(sf::Vector2f(400, 400), waypoints),
new EnemyTemplate(this, "enemySprite", 1, 2, false,
sf::Vector2f(400, 400)), spawnParams));
//*/
// Skipping irrelevant code
}
即使我理解了声明和定义的基础知识,我仍然感到难过。有什么办法可以解决这个问题
答案 0 :(得分:0)
我在大写时遇到了类似的错误:
ZDEPARTMENT01-DEPHEAD
VS
public static String encrypt(String plainText) throws Exception
{
Security.addProvider(new BouncyCastleProvider());
String pub = "-----BEGIN PUBLIC KEY-----"+
"\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtUS7ZJpnbcu8B+mfGrr0Gz6A23lS893mEFNnuR+frbtWDsoIHTfN4yhfbslkzsAMp3ENvM6Ic/0nHEvftrZxFXSrN7n3xZ+mdzOV/u8rqZoB7MEu6mZvdg3zfj7dGglq/fqlYxzHLlxDHjeCrY0dSD0ZAX1zCm3IZ0ufbMBqTrsSaHAuDlIXaQlJXmz3/Y+YfynJZXth/ats1gTBQhMIU9lWutMa4iKkeehn+P9ja4pC9NUlB9W4pojF2Qs+pY4kgTb9+SP8WjnhoSAmJMQGbYwY3HOZyfuOqAmdjoh9Y0LEZ3tq5NGD0b+T7L+P/FuIzvjYZYq6g/FaWaPcVrVLpwIDAQAB"+
"\n-----END PUBLIC KEY-----";
System.out.println(pub);
String strt= pub;
StringReader fileReader= new StringReader(strt);
PEMReader pemReader= new PEMReader(fileReader);
PublicKey pk= (PublicKey)pemReader.readObject();
Cipher c = Cipher.getInstance(RSA_ECB_PKCS5);
PublicKey publicKey = pk;
c.init(Cipher.ENCRYPT_MODE, transformKey(publicKey,
"RSA", new BouncyCastleProvider()));
byte[] encValue= new byte[0];
try {
encValue = c.doFinal(plainText.getBytes());
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
String encrypted = DatatypeConverter.printHexBinary(encValue);
System.out.println("Encrypted value: "+encrypted);
return encrypted;
}
标题保护可以说是由#include "sceneGame.hpp"
提供的。这是避免循环依赖的好主意。有些编译器支持#include "SceneGame.hpp"
指令,这是#pragma once
的一种有保障的替代方法。