小编jac*_*111的帖子

C++在范围结束前删除函数指针

如果我有一个功能:

std::string returnString() {
    return "Hello, World!";
}
Run Code Online (Sandbox Code Playgroud)

电话:

std::string hello = returnString();
std::cout << hello << std::endl;
Run Code Online (Sandbox Code Playgroud)

生产Hello, World!.

但是,如果我尝试:

const char* hello = returnString().c_str();
Run Code Online (Sandbox Code Playgroud)

并尝试打印:

for (const char* p = hello; *p; ++p ) {
    std::cout << *p;
}
std::cout << std::endl;
Run Code Online (Sandbox Code Playgroud)

它给我一个错误说Invalid read of size 1,这意味着p是NULL.

是什么导致了这种行为?

谢谢你的帮助.

c++ destructor scope function-pointers

2
推荐指数
1
解决办法
128
查看次数

如何使用 OpenGL 在 Gtk+ 中进行 3D 渲染?

我一直在互联网上搜索很多在我的 Gtk 应用程序中使用 3D 图形的方法,并且我找到了 Gtk Glarea,但我找不到任何教程。有人有什么建议吗?

c++ opengl gtk3

1
推荐指数
1
解决办法
4260
查看次数

标签 统计

c++ ×2

destructor ×1

function-pointers ×1

gtk3 ×1

opengl ×1

scope ×1