用delete释放int ab = *new int;语句创建的空间
时间: 2023-12-23 18:05:28 浏览: 49
可以使用以下语句释放:
```
delete &ab;
```
需要注意的是,使用 `delete` 释放的空间必须是使用 `new` 申请的空间,并且在释放之前需要先将指向该空间的指针置为 `nullptr`,以避免出现悬空指针。此外,释放的空间需要与申请时的内存对齐方式一致,即申请时使用 `new` 的对齐方式应该与释放时使用 `delete` 的对齐方式相同。
相关问题
{ "id": "0050d3b64520efc0", "type": "tab", "label": "sqlserver", "disabled": false, "info": "", "env": [] }, { "id": "50444b205365b7b1", "type": "inject", "z": "0050d3b64520efc0", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 430, "y": 160, "wires": [ [ "05980f64a43546e3" ] ] }, { "id": "205e1dc78be2b277", "type": "debug", "z": "0050d3b64520efc0", "name": "debug 124", "active": true, "tosidebar": true, "console": true, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 840, "y": 160, "wires": [] }, { "id": "0623f8dda03d7cd7", "type": "comment", "z": "0050d3b64520efc0", "name": "sqlserver 创建表", "info": "", "x": 160, "y": 160, "wires": [] }, { "id": "05980f64a43546e3", "type": "MSSQL", "z": "0050d3b64520efc0", "mssqlCN": "49a8339514344c57", "name": "", "query": "CREATE TABLE [user2] (id VARCHAR(128) NOT NULL,name VARCHAR(128) DEFAULT NULL,pass VARCHAR(128) DEFAULT NULL,create_time DATETIME DEFAULT GETDATE(),update_time DATETIME DEFAULT GETDATE(),PRIMARY KEY (id));", "outField": "payload", "x": 640, "y": 160, "wires": [ [ "205e1dc78be2b277" ] ] }, { "id": "90aef4487e33db0f", "type": "comment", "z": "0050d3b64520efc0", "name": "sqlserver 插入值(固定值)", "info": "", "x": 200, "y": 460, "wires": [] }, { "id": "a63859c171ea7853", "type": "inject", "z": "0050d3b64520efc0", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 430, "y": 460, "wires": [ [ "f2388da6cc16b183" ] ] }, { "id": "7bd4974d9b1b2336", "type": "debug", "z": "0050d3b64520efc0", "name": "debug 125", "active": true, "tosidebar": true, "console": true, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 840, "y": 460, "wires": [] }, { "id": "f2388da6cc16b183", "type": "MSSQL", "z": "0050d3b64520efc0", "mssqlCN": "49a8339514344c57", "name": "", "query": "INSERT INTO [user2] (id, name, pass)\nVALUES ('2', 'luvk', '30');", "outField": "payload", "x": 640, "y": 460, "wires": [ [ "7bd4974d9b1b2336" ] ] }, { "id": "82c0cecdbe6cb93d", "type": "comment", "z": "0050d3b64520efc0", "name": "sqlserver 更新语句", "info": "", "x": 170, "y": 580, "wires": [] }, { "id": "7ea630879fe10a7c", "type": "inject", "z": "0050d3b64520efc0", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 430, "y": 580, "wires": [ [ "721c3549f471cd91" ] ] }, { "id": "8549f456d149478e", "type": "debug", "z": "0050d3b64520efc0", "name": "debug 126", "active": true, "tosidebar": true, "console": true, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 840, "y": 580, "wires": [] }, { "id": "721c3549f471cd91", "type": "MSSQL", "z": "0050d3b64520efc0", "mssqlCN": "49a8339514344c57", "name": "", "query": "UPDATE [user2]\nSET name = 'cc'\nWHERE id = 1;", "outField": "payload", "x": 640, "y": 580, "wires": [ [ "8549f456d149478e" ] ] }, { "id": "247d024ec99b6548", "type": "inject", "z": "0050d3b64520efc0", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 430, "y": 260, "wires": [ [ "3d8078187ea32c21" ] ] }, { "id": "d93cc43727388ca4", "type": "debug", "z": "0050d3b64520efc0", "name": "debug 127", "active": true, "tosidebar": true, "console": true, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 840, "y": 260, "wires": [] }, { "id": "93265186c022908e", "type": "comment", "z": "0050d3b64520efc0", "name": "sqlserver 创建触发器create_time", "info": "", "x": 210, "y": 260, "wires": [] }, { "id": "3d8078187ea32c21", "type": "MSSQL", "z": "0050d3b64520efc0", "mssqlCN": "49a8339514344c57", "name": "", "query": "-- 创建触发器\nCREATE TRIGGER [user2_after_insert_trigger]\nON [user2]\nAFTER INSERT\nAS\nBEGIN\n UPDATE [user2]\n SET create_time = GETDATE()\n WHERE id IN (SELECT id FROM inserted);\nEND;\n\n", "outField": "payload", "x": 640, "y": 260, "wires": [ [ "d93cc43727388ca4" ] ] }, { "id": "afffde3e03143b47", "type": "inject", "z": "0050d3b64520efc0", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 430, "y": 360, "wires": [ [ "fd2b020e28f720fc" ] ] }, { "id": "432d297b7b56b66b", "type": "debug", "z": "0050d3b64520efc0", "name": "debug 128", "active": true, "tosidebar": true, "console": true, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 840, "y": 360, "wires": [] }, { "id": "da86016c2ecaeabe", "type": "comment", "z": "0050d3b64520efc0", "name": "sqlserver 创建触发器update_time", "info": "", "x": 210, "y": 360, "wires": [] }, { "id": "fd2b020e28f720fc", "type": "MSSQL", "z": "0050d3b64520efc0", "mssqlCN": "49a8339514344c57", "name": "", "query": "CREATE TRIGGER [user2_after_update_trigger]\nON [user2]\nAFTER UPDATE\nAS\nBEGIN\n UPDATE [user2]\n SET update_time = GETDATE()\n WHERE id IN (SELECT id FROM inserted);\nEND;\n\n", "outField": "payload", "x": 640, "y": 360, "wires": [ [ "432d297b7b56b66b" ] ] }, { "id": "b85037e9a7c7adeb", "type": "comment", "z": "0050d3b64520efc0", "name": "sqlserver 查看语句", "info": "", "x": 170, "y": 680, "wires": [] }, { "id": "e8137588ad614ddb", "type": "inject", "z": "0050d3b64520efc0", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 430, "y": 680, "wires": [ [ "5e12a9e7cbe29d1c" ] ] }, { "id": "8f81bce657ac3e85", "type": "debug", "z": "0050d3b64520efc0", "name": "debug 129", "active": true, "tosidebar": true, "console": true, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 830, "y": 680, "wires": [] }, { "id": "5e12a9e7cbe29d1c", "type": "MSSQL", "z": "0050d3b64520efc0", "mssqlCN": "49a8339514344c57", "name": "", "query": "select * from [user];", "outField": "payload", "x": 640, "y": 680, "wires": [ [ "8f81bce657ac3e85" ] ] }, { "id": "c45827576367c305", "type": "comment", "z": "0050d3b64520efc0", "name": "sqlserver 删除语句", "info": "", "x": 170, "y": 780, "wires": [] }, { "id": "e50bd5706ed4e109", "type": "inject", "z": "0050d3b64520efc0", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 430, "y": 780, "wires": [ [ "db6f27bb68271e21" ] ] }, { "id": "6ab8984efdf4fe38", "type": "debug", "z": "0050d3b64520efc0", "name": "debug 130", "active": true, "tosidebar": true, "console": true, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 830, "y": 780, "wires": [] }, { "id": "db6f27bb68271e21", "type": "MSSQL", "z": "0050d3b64520efc0", "mssqlCN": "49a8339514344c57", "name": "", "query": "DELETE FROM [user2]\nWHERE id = 2;\n", "outField": "payload", "x": 640, "y": 780, "wires": [ [ "6ab8984efdf4fe38" ] ] }, { "id": "49a8339514344c57", "type": "MSSQL-CN", "name": "", "server": "127.0.0.1", "encyption": true, "database": "mssql_jk" }]
### 创建表
在 SQL Server 中,创建新表使用 `CREATE TABLE` 语句。此命令允许定义列名、数据类型以及其他约束条件。
```sql
CREATE TABLE Student (
StudentID INT PRIMARY KEY,
Name NVARCHAR(50),
GraduationYear SMALLINT
);
```
### 插入记录
向已存在的表中添加新的行可通过 `INSERT INTO` 命令完成。这会指定目标表格名称及其字段列表,并提供相应的值集合。
```sql
INSERT INTO Student (StudentID, Name, GraduationYear)
VALUES (1, N'张三', 2023), (2, N'李四', 2024);
```
### 更新记录
为了更改现有条目内的某些属性或者全部内容,则需要用到 `UPDATE` 指令。它能够定位特定的记录并通过设置子句改变其特性。
```sql
UPDATE Student SET GraduationYear = 2025 WHERE StudentID = 1;
```
### 创建触发器
触发器是一种特殊的存储过程,在发生指定事件时自动激活并运行预设逻辑。下面的例子展示了当从 `Student` 表删除某位学员的信息时同步清除关联书籍借用历史的功能[^2]:
```sql
CREATE TRIGGER triDeStudent ON Student FOR DELETE AS
BEGIN
DELETE BorrowRecord
FROM BorrowRecord br JOIN DELETED d ON br.StudentID = d.StudentID;
END;
```
### 删除记录
移除数据库里的单个或多个实例可借助于 `DELETE FROM` 结构实现。通过附加适当的选择标准来限定受影响范围。
```sql
DELETE FROM Student WHERE StudentID = 1;
```
上述操作涵盖了基本 CRUD 功能(Create, Read, Update, Delete),并且引入了触发器机制用于维护不同实体间的一致性和完整性关系。
阅读全文
相关推荐
















