【发布时间】:2016-08-23 21:22:09
【问题描述】:
我正在使用 Microsoft Visual Studio Community 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)'
interprocess.hpp
namespace pr
{
(...)
void InitPreySplitPipe();
(...)
}
interprocess.cpp
#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;
}
}
(...)
}
// 函数应该在哪里调用
game_local.cpp
(...)
#include "../PreyRun/interprocess.hpp"
pr::InitPreySplitPipe();
(...)
【问题讨论】:
-
c-tag 有什么特别的原因,还是你只是觉得这个标签美观? -
获得此错误的一种方法是在全局范围内进行调用,在任何函数之外。另一种是循环包含,其中两个 .hpp 文件尝试相互包含。
标签: c++ visual-c++ dll compiler-errors