如何解决C++ 中不允许使用限定名称,已在 C++ 17 中编译
我正在尝试关注 John Horton 在 Beginning C++ Game Programming 中的 Zombie Arena 项目。 但是,Pickup.h 给我带来了问题。
class Pickup
{
private:
//Start value for health pickups
const int HEALTH_START_VALUE = 50;
const int AMMO_START_VALUE = 12;
const int START_WAIT_TIME = 10;
const int START_SECONDS_TO_LIVE = 5;
// The sprite that represents this pickup
Sprite m_Sprite;
// The arena it exists in
IntRect m_Arena;
// How much is this pickup worth?
int m_Value;
// What type of pickup is this?
// 1 = health,2 = ammo
int m_Type;
// Handle spawning and disappearing
bool m_Spawned;
float m_SecondsSinceSpawn;
float m_SecondsSinceDeSpawn;
float m_SecondsToLive;
float m_SecondsToWait;
// Public prototypes go here
public:
Pickup::Pickup(int type);
// Prepare a new pickup
void setArena(IntRect arena);
void spawn();
// Check the position of a pickup
FloatRect getPosition();
// Get the sprite for drawing
Sprite getSprite();
// Let the pickup update itself each frame
void update(float elapsedTime);
// Is this pickup currently spawned?
bool isSpawned();
// Get the goodness from the pickup
int gotIt();
// Upgrade the value of each pickup
void upgrade();
};
当我尝试编译程序时,我从 Pickup::Pickup(int type)
的成员声明错误中得到一个非法限定名称。可能有什么问题?我试图调试这个没有成功。请帮忙。我已经在用 C++ 17 编译了。
解决方法
代替构造函数的这个声明
[hallo: {'name': 'Peter','lastname': 'Richard'}]
写
Pickup::Pickup(int type);
构造函数声明的限定名称不正确,但据我所知,某些编译器(如 MS VS)允许此类声明。
您可以在类定义之外的成员函数定义中使用成员函数的限定名称。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。