我真的是这个傻瓜:这= 0x7ffffffe

n00*_*00b 2 c++ visual-c++

我有一个非常简单的类存根 - 我刚开始制作它:

class CJSScript
{
public:
    CJSScript(std::string scriptfile);
    ~CJSScript(void);
private:
    std::string scriptname;
};
CJSScript::CJSScript(std::string scriptfile)
{
    size_t found = scriptfile.find_last_of("/\\");
    scriptname = scriptfile.substr(found+1);
    printf("should load %s now...", scriptname);

}
Run Code Online (Sandbox Code Playgroud)

但是在那个构造函数中我得到了一个异常,this显然是设置为0x7ffffffe

主要方案是

int _tmain(int argc, _TCHAR* argv[])
{
    CJSScript* test=new CJSScript("./script/test.js");
  system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这到底是怎么回事.我以为我很久以前就已经有了基础知识,但这是一种妥协.我或编译器:)

调试器转储:

Win32Project3.exe!_output_l(_iobuf * stream, const char * format, localeinfo_struct * plocinfo, char * argptr) Line 1649    C++
Win32Project3.exe!printf(const char * format, ...) Line 62  C
Win32Project3.exe!CJSScript::CJSScript(std::basic_string<char,std::char_traits<char>,std::allocator<char> > scriptfile) Line 11 C++
Win32Project3.exe!wmain(int argc, wchar_t * * argv) Line 38 C++
Win32Project3.exe!__tmainCRTStartup() Line 240  C
Run Code Online (Sandbox Code Playgroud)

Joh*_*ing 6

printf不知道如何处理string对象.你需要传递一个const char*:

 printf("should load %s now...", scriptname.c_str());
Run Code Online (Sandbox Code Playgroud)

这是类型安全的问题.出于这个原因,我更喜欢使用流.

cout << "should load " << scriptname << " now...";
Run Code Online (Sandbox Code Playgroud)