宏
ifndef + define + endif
用#pragma once
即可!
如果__XXX_H__
未定义,才会执行#define
到#endif
段的代码,防止重复定义。
| #ifndef __MODEL_H__ |
| #define __MODEL_H__ |
| |
| |
| class Model { |
| |
| }; |
| |
| #endif |
模板template
| |
| |
| |
| |
| template <size_t LEN, size_t DIM, typename T> |
| vec<LEN, T> embed(const vec<DIM, T> &v, T fill = 1) { |
| vec<LEN, T> ret; |
| for (size_t i = LEN; i--; ret[i] = (i < DIM ? v[i] : fill)); |
| return ret; |
| } |
类
virtual
=0
纯虚函数,子类必须实现此方法,此时IShader
无法被实例化?
没有=0,一般都是父类也有实现方法
| struct IShader { |
| virtual ~IShader(); |
| virtual Vec4f vertex(int iface, int nthvert) = 0; |
| |
| virtual bool fragment(Vec3f bar, TGAColor &color) = 0; |
| }; |
销毁函数 ~Class_Name();
&func_name
- 重载运算符
- 链式调用,超过1次调用,如
MyClass.setA().setB();
| class MyClass { |
| public: |
| MyClass &operator=(const MyClass &other) { |
| if (this != &other) { |
| |
| } |
| return *this; |
| } |
| MyClass &setA(int a) { |
| this->a = a; |
| return *this; |
| } |
| }; |
内存
- varname = new char[255];
- delete[] varname;
本文作者:Nolca
本文链接:https://www.cnblogs.com/nolca/p/18677268
版权声明:本作品采用 收益分享revenue sharing 许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步