CMakeTutorialStep1 2.3.12
Loading...
Searching...
No Matches
tutorial.cxx File Reference

step1 主程序:读命令行数值、调用 TutorialMath 求平方根并打印。 More...

#include <algorithm>
#include <cstddef>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <numeric>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#include "CMakeTutorialConfig.hxx"
#include "ScenarioLog.hxx"
#include "TutorialMath.hxx"

Classes

struct  hash_Person
 人员结构 + std::hash 特化演示(自定义类型可入无序容器)。 More...
class  di_Printer
 依赖注入演示:输出接口(构造函数注入进 di_MessageService)。 More...
class  di_MessageService
 依赖注入演示:持有 di_Printer 引用,不自行创建依赖。 More...
struct  std::hash< hash_Person >

Namespaces

namespace  std

Functions

void passByValue (int x)
 按值传递:形参修改不影响实参。
void passByReference (int &x)
 按引用传递:函数内修改直接作用于实参。
void modifyValue (const int &value)
 常量引用传递:只读访问,禁止修改(编译器强制)。
int main (int argc, char *argv[])
 程序入口:校验参数 → compute_sqrt → 打印 CMake 注入的宏与版本信息。
void log_error (std::string_view msg)
 写 ERROR 级日志并触发裁剪
void log_info (std::string_view msg)
 写 INFO 级日志并触发裁剪
void log_sep ()
 输出分隔线(经 log_info)

Detailed Description

step1 主程序:读命令行数值、调用 TutorialMath 求平方根并打印。

运行日志经 ScenarioLog 写入 log/exe.log(【不可删除】见 ScenarioLog.hxx/.cxx)。

Function Documentation

◆ log_error()

void scenario_log::log_error ( std::string_view msg)

写 ERROR 级日志并触发裁剪

◆ log_info()

void scenario_log::log_info ( std::string_view msg)

写 INFO 级日志并触发裁剪

◆ log_sep()

输出分隔线(经 log_info)

◆ main()

int main ( int argc,
char * argv[] )

程序入口:校验参数 → compute_sqrt → 打印 CMake 注入的宏与版本信息。

Parameters
argc命令行参数个数
argv命令行参数数组(argv[1] 为待开平方的数值)
Returns
0 成功;1 缺少参数;2 输入非法(负数 / 超出上限)

◆ modifyValue()

void modifyValue ( const int & value)

常量引用传递:只读访问,禁止修改(编译器强制)。

Parameters
value只读引用

◆ passByReference()

void passByReference ( int & x)

按引用传递:函数内修改直接作用于实参。

Parameters
x传入引用

◆ passByValue()

void passByValue ( int x)

按值传递:形参修改不影响实参。

Parameters
x传入值(副本)