我有一个非常简单的类 stub ——我刚刚开始制作它:
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);
}
但是在那个构造函数中我得到一个异常,this
显然设置为 0x7ffffffe
主要程序是
int _tmain(int argc, _TCHAR* argv[])
{
CJSScript* test=new CJSScript("./script/test.js");
system("pause");
return 0;
}
这到底是怎么回事。我以为我很久以前就掌握了基础知识,但这是一种妥协。我或编译器:)
调试器转储:
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
最佳答案
printf
不知道如何处理 string
对象。您需要传递一个 const char*
:
printf("should load %s now...", scriptname.c_str());
这是类型安全的问题。出于这个原因,除其他外,我更喜欢使用流。
cout << "should load " << scriptname << " now...";
关于c++ - 我真的这么蠢吗: this = 0x7ffffffe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12940661/