gpt4 book ai didi

c++ - 错误 : the global scope has no GetUrl

转载 作者:行者123 更新时间:2023-11-28 08:26:02 26 4
gpt4 key购买 nike

我的 C++ DLL 有一个新问题...我尝试导出整个类而不是只导出一个方法。但是程序现在不想编译,因为全局范围没有 GetUrl
这是我的“UrlConnector.h”:

#define ConnectMe __declspec( dllexport )<p></p>

<p>namespace ConnectHttps
{
class ConnectMe
{
void GetUrl(char *url, unsigned int bufferLength);
};
}
</p>

这是我的 UrlConnector.cpp 中未编译的部分:
<pre>#include "UrlConnector.h"
#include "MyConnectionClass.h"
#include
using namespace std;<p></p>

<p>namespace ConnectHttps
{
void ConnectMe::GetUrl(char* url, unsigned bufferLength)
{
MyConnectionClass initSec;
string response = initSec.GetResult();
strncpy_s(url, bufferLength, response.c_str(), response.length());
}
}
</p></pre>
现在,我希望能够从中创建一个 DLL,并且我想制作一个测试程序来从 dll 中调用类和方法 GetUrl。我正在使用带有 Visual C++ DLL 的 Visual Studio 2010。
我还设法阅读了 this from the MSDNthis tutorial同样,但我似乎无法让它工作!如果有任何帮助,我将不胜感激!

最佳答案

除非我弄错了,否则您似乎没有给您的类(class)命名。你让 ConnectMe 不是一个类名而是一个宏来导出你的类,但是你的类应该有一个名字

也许试试

#define EXPORT_IT __declspec( dllexport )

namespace ConnectHttps
{
class EXPORT_IT ConnectMe
{
void GetUrl(char *url, unsigned int bufferLength);
};
}

我也不是 100% 确定这一点,因为我目前无法访问编译器,但输入:

namespace ConnectHttps {
...
}

您的 .cpp 文件不正确。相反,你应该:

void ConnectHttps::ConnectMe::GetUrl(char* url, unsigned bufferLength)
{
MyConnectionClass initSec;
string response = initSec.GetResult();
strncpy_s(url, bufferLength, response.c_str(), response.length());
}

关于c++ - 错误 : the global scope has no GetUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4043385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com