【发布时间】:2010-11-02 12:02:24
【问题描述】:
大家好,
我今天遇到了一个非常奇怪的问题,我不确定是什么原因造成的。这是我用来获取当前工作目录的函数:
#ifdef _WIN32
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#error "There is currently no support for non windows based systems!"
#endif
const std::string getCurrentPath()
{
char CurrentPath{_MAX_PATH];
GetCurrentDir(CurrentPath, _MAX_PATH);
CurrentPath[_MAX_PATH - 1] = '/0';
return std::string(CurrentPath);
}
此函数作为独立函数运行良好。但是,如果我将其声明为类中的静态函数:
static __declspec(dllexport) const std::string getCurrentPath(void);
和一个 .dll,当我尝试这样做时,我得到“调试断言失败错误”
std::cout<<CUtilities::getCurrentPath()<<std::endl;
如果我改为写:
std::string dir = CUtilities::getCurrentPath();
std::cout<<"Dir is : "<<dir<<std::endl;
它工作正常。我对自己做错了什么感到完全困惑。有什么想法吗?
【问题讨论】: