繁体   English   中英

为什么我的带有Connector / C ++的函数在返回线上崩溃?

[英]why does my function with connector/c++ crash on the return line?

此函数在返回行上崩溃:

string questionmsg(string user, sql::Statement *stmt)
{

sql::ResultSet *res;// ...
res = stmt->executeQuery("SELECT questionmsg FROM `life-checker` WHERE `user` = '" + user + "';");
res->next();
string id = res->getString(1);

delete res;
delete stmt;

return id; //crash here - Unhandled exception Access violation
}

这是主要的:

int main()
{
    sql::mysql::MySQL_Driver *driver;
    sql::Connection *con;
    sql::Statement *stmt;

    // ...
    driver = sql::mysql::get_mysql_driver_instance();
    cout<<"Connecting to database...\n";
con = driver->connect("tcp://xxx.xxx.xxx.xxx:3306", "xxxxx_user", "xxxxx_pass!");
con->setSchema("mrhowtos_main");

stmt = con->createStatement();
// ...



cout << questionmsg("Nolan", stmt);




delete con;
cout<<"done\n";
system("PAUSE");
    return 0;
}

我正在逐步查看程序中的变量。 id = res-> getString(1);的结果 正是我所期望的,一句话。 所以我不知道为什么它崩溃。 我在观看变量时注意到的一件事是经过删除res和stmt行之后。 监视框中的变量值不会更改,就像它实际上并未删除它们一样。 但是我不知道那应该是怎么出现的。

您确定您拥有用于res的内存吗? 同样对于字符串ID,它仍然可以指向您已经释放的空间吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM