08 2023 档案
摘要:使用智能指针释放在堆上分配的内存(超出作用域就释放) class Entity { private: float x, y; public: Entity(float x,float y):x(x),y(y) { std::cout<<"Created Entity!"<<std::endl; }
阅读全文
摘要:再数据结构内重载它的操作符,一般会先写一个函数,然后再重载符号:返回类型+operator+重载符号(参数){//定义} Vector2 Multity(const Vector2& other)const { return Vector2(x * other.x, y * other.y); }
阅读全文
摘要:递归 TreeNode* dfs(TreeNode* root,TreeNode* p,TreeNode* q){ if(!root)return root;//当发现这个节点已经是叶节点时,要告诉上层 if(root==p||root==q)return root;//当发现是p节点或者q时也要告
阅读全文
摘要:当构造函数只有一个构造函数时,可以直接将参数赋值给类对象 class Entity { public: String m_Name; int m_Age; public: explicit Entity(const String& name) :m_Name(name) ,m_Age(0){} En
阅读全文
摘要:在堆上的类对象或者任何变量,一旦声明将会一直存在,直到手动释放 使用new关键字,使用delete释放;可以显示控制生存期 数组使用delete删除时也要使用delete [ ] a; new关键字作用:1.在堆上分配内存 2.调用类的构造函数 new还能指定分配内存的位置 class Entity
阅读全文
摘要:bfs+dp unordered_map<TreeNode* ,int>d,p; queue<pair<TreeNode* ,TreeNode*>>q; int dp(TreeNode* root){ d[root]=p[root]=0; q.push({root,nullptr}); while(
阅读全文