DLL 语法错误

DLL syntax error

本文关键字:错误 语法 DLL      更新时间:2023-10-16

我正在尝试在Visual C++ 2010中创建具有多个函数的dll,并且不断收到与使用字符串相关的语法错误,或者看起来是这样。

1>c:usersnewdocumentsvisual studio 2010projectsgetintgetintgetint.h(9): error C2061: syntax error : identifier 'string'

代码如下所示。我真的按照上次做了什么;尽管我制作的最后一个 DLL 有 1 个函数并且没有布尔值或字符串值。

#include <string>
class getInt
{
public:
    //NB :: static __declspec(dllexport) is need to export data from the dll!
    //This declares the function for retrieving an integer value from the user
    static __declspec(dllexport) int toInt (const string &inStr);
    static __declspec(dllexport) int getNum();
    static __declspec(dllexport) bool isValidInt (const string& str);
};

还有其他几个语法错误,但我相信它们是由于字符串在其他函数之前而引起的。

全局

范围内没有string类,只有 std 命名空间中的类。因此,将函数更改为接受 std::string s。

#include <string>
class getInt
{
public:
    //NB :: static __declspec(dllexport) is need to export data from the dll!
    //This declares the function for retrieving an integer value from the user
    static __declspec(dllexport) int toInt (const std::string &inStr);
    static __declspec(dllexport) int getNum();
    static __declspec(dllexport) bool isValidInt (const std::string& str);
};

string位于std命名空间中,因此前缀为std::

#include <string>
class getInt
{
public:
    //NB :: static __declspec(dllexport) is need to export data from the dll!
    //This declares the function for retrieving an integer value from the user
    static __declspec(dllexport) int toInt (const std::string &inStr);
    static __declspec(dllexport) int getNum();
    static __declspec(dllexport) bool isValidInt (const std::string& str);
};