具有类型的静态函数缺少类型说明符

Missing type specifier on a static function with a type

本文关键字:类型 说明符 静态函数      更新时间:2023-10-16

我的问题涉及三个文件以及它们之间的关系:在一个文件中,我有一堆预定义的类型,如Uintint32等。在另外两个中,我有一个类,用于对异常(主要是静态函数)和类的定义进行分类。

所有类型都在文件Types.h中,其中有一个宏允许全局定义类型:

namespace Enigma {
    //Omitted Types
    typedef std::uint32_t Uint32;
    typedef std::string   string;
    //Omitted Types
}
#if defined(USING_GLOBAL_TYPES)
using namespace aNamespace;
#endif

在其他文件中,我有以下内容(或者类似的内容):

头文件:

#include "Types.h"
namespace Enigma {
class ExceptionCategory {
    typedef Uint32 CategoryID;
    static CategoryID GetIDFromName(const string& name) noexcept;
};
}

源文件:

Engima::ExceptionCategory::CategoryID Enigma::ExceptionCategory::GetIDFromName(const string& name) noexcept {
//Omitted Code
}

现在,根据编译器向我抛出的错误消息,问题出现在源文件中,其中包括以下信息:

错误C4430:缺少类型说明符-假定为int。注意:C++不支持默认的int

错误C2143:语法错误:在"&"之前缺少","

错误C2511:"Enigma::ExceptionCategory::IDType Enigma::ExceptionCatalog::GetIDFromName(const int)noexcept":在"Enigma::ExcessionCategory"中找不到重载的成员函数

编辑:主要改写

在cpp文件中,删除命名空间前的双冒号。

aNamespace::int32 aNamespace::aClass::aStaticFunction() noexcept {
    //does a thing
}

一个非常简单的错误:
在源代码中string之前缺少命名空间Enigma
这是不寻常的,因为它已经工作了很长时间,直到突然停止工作

Engima::ExceptionCategory::CategoryID Enigma::ExceptionCategory::GetIDFromName(const Enigma::string& name) noexcept {
    //Omitted Code
}