小编Lan*_*ndP的帖子

cppreference.com 中的这段话(默认参数)是什么意思?

来自默认参数的 cppreference 页面:

默认参数中不允许使用非静态类成员(即使未对它们求值),除非用于形成指向成员的指针或在成员访问表达式中:

int b;
class X
{
    int a;
    int mem1(int i = a); // error: non-static member cannot be used
    int mem2(int i = b); // OK: lookup finds X::b, the static member
    static int b;
};
Run Code Online (Sandbox Code Playgroud)

我无法理解“除非用于形成指向成员的指针或在成员访问表达式中”。并且例子中没有给出相关代码。

c++ default-arguments

5
推荐指数
1
解决办法
137
查看次数

标签 统计

c++ ×1

default-arguments ×1