相关疑难解决方法(0)

如何在宏中引用参数?

我想创建一个C预处理器宏,它将引用该参数.就像常用的一样#X.

我想Q(A)扩大到'A'.

我在Linux上使用gcc.

有人有想法吗?

我知道#双引号.我正在寻找一种类似的单引号机制.

gcc stringification c-preprocessor

10
推荐指数
2
解决办法
4038
查看次数

如何基于变量值习惯性地调用C++函数?

假设我有一个数据类型enum TreeTypes { TallTree, ShortTree, MediumTree }.

我必须根据一种特定的树类型初始化一些数据.

目前我已经写了这段代码:

int initialize(enum TreeTypes tree_type) {
    if (tree_type == TallTree) {
        init_tall_tree();
    }
    else if (tree_type == ShortTree) {
        init_short_tree();
    }
    else if (tree_type == MediumTree) {
        init_medium_tree();
    }
    return OK;
}
Run Code Online (Sandbox Code Playgroud)

但这是某种愚蠢的代码重复.我没有使用任何强大的C++功能,如模板.

我怎么能更好地编写这段代码?

谢谢,Boda Cydo.

c++ templates repeat

5
推荐指数
2
解决办法
2556
查看次数

标签 统计

c++ ×1

c-preprocessor ×1

gcc ×1

repeat ×1

stringification ×1

templates ×1