首页 > TAG信息列表 > default-arguments

c-指针的正确无效值是什么?

假设我有这段代码.基本的“如果呼叫者未提供值,请计算值”方案. void fun(const char* ptr = NULL) { if (ptr==NULL) { // calculate what ptr value should be } // now handle ptr normally } 并用 fun(); // don't know the value yet, let fun wor

在C函数中跳过一些参数?

我有一个C函数有5个参数,所有参数都有默认值.如果我传入前三个参数,程序将为最后两个参数分配一个默认值.有没有办法传递3个参数,并在中间跳过一个,给出值,比如第一,第二和第五个参数?解决方法:不是直接的,但你可以用std :: bind做一些事情: int func(int arg1 = 0, int arg2 = 0, i

在C中放置默认参数值的位置?

参见英文答案 > Default value of function parameter                                    4个 默认参数值的位置是什么?只是在函数定义,声明或两个地方?解决方法:默认参数值必须出现在声明中,因为这是调用者看到的唯一内容. 编辑:正如其他人指

如何将实例成员的默认参数值传递给方法?

我想使用实例的属性值将默认参数传递给实例方法: class C: def __init__(self, format): self.format = format def process(self, formatting=self.format): print(formatting) 尝试时,我收到以下错误消息: NameError: name 'self' is not defined 我

如何在python中重写方法默认参数?

方法默认参数可以显然被覆盖: >>> class B: ... def meth(self, r=True): print r >>> class D(B): ... def meth(self, r=False): print r ... D().meth() False >>> B().meth() True 这怎么可能 ?它被认为是不好的风格?解决方法:您可以以任意方式更改重写方法的签名. Pyth

python – 指定存在/不存在的默认参数的惯用方法

我经常看到python代码采用默认参数,并且在未指定时具有特殊行为. 如果我想要这样的行为: def getwrap(dict, key, default = ??): if ???: # default is specified return dict.get(key, default) else: return dict[key] 如果我要自己动手,我最终会得到

c – 从指针转换为非标量对象类型?

有人可以解释为什么以下工作,尝试以下代码,它工作正常. class A { public : int32_t temp ; A ( bool y = false ) { } } ; int main ( int argc, char *argv[] ) { A temp ; temp = new A () ; temp.temp = 5 ; std::cout << " " << temp.temp <<