#include"Gun.h"#include"iostream"usingnamespacestd;voidGun::addBullet(intbullet_num){this->_bullet_count+=bullet_num;}boolGun::shoot(){if(this->_bullet_count<=0){cout<<"There is no bullet!"<<endl;returnfalse;}this->_bullet_count-=1;cout<<"shoot success"<<endl;returntrue;}
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version":"0.2.0","configurations":[{"name":"(gdb) 启动","type":"cppdbg","request":"launch","program":"输入程序名称,例如 ${workspaceFolder}/a.out","args":[],"stopAtEntry":false,"cwd":"${fileDirname}","environment":[],"externalConsole":false,"MIMode":"gdb","setupCommands":[{"description":"为 gdb 启用整齐打印","text":"-enable-pretty-printing","ignoreFailures":true}]}]}
{// See https://go.microsoft.com/fwlink/?LinkId=733558// for the documentation about the tasks.json format"version":"2.0.0","tasks":[{"label":"echo","type":"shell","command":"echo Hello"}]}
{// See https://go.microsoft.com/fwlink/?LinkId=733558// for the documentation about the tasks.json format"version":"2.0.0","options":{"cwd":"${workspaceFolder}/build"},"tasks":[{"type":"shell","label":"cmake","command":"cmake","args":[".."]},{"label":"make","group":{"kind":"build","isDefault":true},"command":"make","args":[]},{"label":"build","dependsOrder":"sequence","dependsOn":["cmake","make"]}],}
在以上的任务配置内容中,我们定义了三个任务。首先是定义了 cmake 预编译指令,其次是定义 make 编译指令,再定义 build 任务去包含预编译和编译这两个步骤。最终修改launch.json 文件如下内容
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version":"0.2.0","configurations":[{"name":"(gdb) 启动","type":"cppdbg","request":"launch","program":"${workspaceFolder}/build/a.out","args":[],"stopAtEntry":false,"cwd":"${fileDirname}","environment":[],"externalConsole":false,"MIMode":"gdb","setupCommands":[{"description":"为 gdb 启用整齐打印","text":"-enable-pretty-printing","ignoreFailures":true}],"preLaunchTask":"build"}]}