C++中不允许使用限定名称,该名称已在C++17中编译

Qualified name is not allowed in C++, already compiling in C++ 17

本文关键字:C++17 编译 不允许 定名称 C++      更新时间:2024-09-28

我正在努力学习John Horton的Beginning C++Game Programming中的Zombie Arena项目。然而,皮卡给我带来了麻烦。

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进行编译了。

而不是构造函数的声明

Pickup::Pickup(int type);

写入

Pickup(int type);

构造函数声明的限定名是不正确的,尽管据我所知,一些编译器(如MSVS(允许这样的声明。

可以在类定义之外的成员函数定义中使用成员函数的限定名。