c++ -类似于python中的关键字
C++ - something like with keyword in python
我有一些关于opengl着色器的抽象,我想这样使用它们:
WITH_SHADER(shader_name) {
// here will be gl commands
}
它应该自动绑定/取消绑定当前gl上下文的着色器。在复合语句之前绑定,之后解绑定。
我可以在c++中构建这个宏吗?
最接近的是RAII。
构建一个类WithShader
封装你的着色器:
- 在构造器中绑定着色器
- 在析构函数 中取消绑定
使用例子:
{
with_shader ws(shader_name)
// use your shader
}
// binding and unbinding occured automatically, thats RAII.
注意:
一般来说,RAII不是微不足道的,要注意复制和赋值构造函数
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- C++中的"inline"关键字
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- Pybind11:将元组列表从Python传递到C++
- 如何确保C++函数在定义之前声明(如override关键字)
- 如何在c++中使用引用实现类似python的行为
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 递归列出所有目录中的C++与Python与Ruby的性能
- IPC使用多个管道和分支进程来运行Python程序
- 从python中调用C++函数并获取返回值
- Python 3.7 和 excess_args 的 SWIG 问题
- Python中的for循环与C++有何不同
- 使用Pybind11向Python公开Eigen::张量
- 为什么python需要全局关键字而C/C++不需要?
- 如何将 'in' 关键字从 python 翻译成 c++?
- 有没有等效于Python的c++"in"关键字?
- 如何使用pybind11传递Python的关键字参数?
- (SWIG c++ to Python)警告301:使用了class关键字,但不在c++模式下
- 如何在c++中使用class中的static关键字来模拟Python中@classmethod的行为
- c++ -类似于python中的关键字