我正在使用Microsoft Visual Studio社区2015 Update 3并且我正在编译一个dll。我想调用函数InitPreySplitPipe我已经尝试用:: pr :: InitPreySplitPipe调用它,我将interprocess.cpp代码复制到game_local.cpp和interprocess.hpp代码到game_local.h并从那里调用但是没有工作任
如果有人感兴趣,我已经设置了GitHub repository所有代码。
感谢阅读并抱歉我的英语不好:/
编译器输出:
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Error C2371 'pr::InitPreySplitPipe': redefinition; different basic types
Error C2556 'int InitPreySplitPipe(void)': overloaded function differs only by return type from 'void pr::InitPreySplitPipe(void)'
namespace pr
{
(...)
void InitPreySplitPipe();
(...)
}
#include "interprocess.hpp"
namespace pr
{
(...)
void InitPreySplitPipe()
{
pipe_preysplit = CreateNamedPipe("\\\\.\\pipe\\" PREYSPLIT_PIPE_NAME,PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS, 1, 256 * 1000, 0, 0, NULL);
if (pipe_preysplit == INVALID_HANDLE_VALUE)
{
return;
}
std::memset(&overlapped, 0, sizeof(overlapped));
overlapped.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
if (overlapped.hEvent == NULL)
{
pipe_preysplit = INVALID_HANDLE_VALUE;
}
}
(...)
}
//应该调用函数
(...)
#include "../PreyRun/interprocess.hpp"
pr::InitPreySplitPipe();
(...)
答案 0 :(得分:0)
在game_local.cpp中:
// PreyRun BEGIN
#include "../PreyRun/interprocess.hpp"
pr::InitPreySplitPipe();
// PreyRun END
您没有从任何内容调用该函数,因此编译器认为它是一个新的函数声明。因此,假定类型int
,其中重载函数int pr:InitPreySplitPipe()
与您的void pr::InitPreySplitPipe()
冲突。这解释了所有3条错误消息。