如何使用double参数或无参数执行C ++函数(How to make a C++ function execute with a double parameter or no parameter)
我有一些代码,我有3个重载函数。 我希望其中一个接受double作为参数,或者如果没有传递参数则调用它。 其他人只接受一个int而另一个接受char,就是这样。 我该怎么做呢?
I have a bit of code and I have 3 overloaded functions. I want one of them to accept a double as a parameter or to be called if there are no passed arguments. The others accept only an int and the other a char, that's it. How would I go about doing that?
原文:https://stackoverflow.com/questions/27995702
最满意答案
我根本不知道您的库,但是根据您显示的内容,您可能希望将
_load_pascal_annotation
的结果分配给新变量,然后访问字典中的boxes
项。 尝试这样的事情:data = d._load_pascal_annotation('{0:06d}'.format(5)) print(data['boxes'])
然而,我要注意的一点是,名称中带有单个前导下划线的方法通常是私有的(例如,它们不是类的公共API的一部分)。 您的
d
对象上可能还有一些其他方法或属性,它们将在后台调用_load_pascal_annotation
(并使用其返回值执行适当的操作)。I don't know your library at all, but from what you've shown, you probably want to assign the results of
_load_pascal_annotation
to a new variable, then access theboxes
item in the dictionary. Try something like this:data = d._load_pascal_annotation('{0:06d}'.format(5)) print(data['boxes'])
One thing I'd note however is that methods with a single leading underscore in their names are generally intended to be private (e.g. they're not part of the class's public API). There may be some other method or attribute on your
d
object that you should be using instead which will call_load_pascal_annotation
in the background (and do something appropriate with its return value).
相关问答
更多-
一个选项可能是.tap方法。 假设你有 x = foo 并想知道foo从外部回报的价值: x = foo.tap { |r| puts r.inspect } 其余的puts r.inspect被写成pr ,它是同一事物的有效简写语法(并且顺便说一句, p返回它的参数,所以在许多情况下,你可以在返回的变量前面简单地粘上一个p - 除了一些语法细节外) 或者,如果您想检查foo内部,并且定义如下所示: def foo # Do stuff something_that_is_returned en ...
-
它不是返回状态,因为这是异步的,甚至在.on代码仍在执行之前就已经返回了。 但是,您可以像这样设置数据变量: loading_asset_status(){ var img = $("img.modal-main-image").attr('src', this.current_image.img_url) .on('load', () => { this.status = (!this.complete || typeof this. ...
-
我根本不知道您的库,但是根据您显示的内容,您可能希望将_load_pascal_annotation的结果分配给新变量,然后访问字典中的boxes项。 尝试这样的事情: data = d._load_pascal_annotation('{0:06d}'.format(5)) print(data['boxes']) 然而,我要注意的一点是,名称中带有单个前导下划线的方法通常是私有的(例如,它们不是类的公共API的一部分)。 您的d对象上可能还有一些其他方法或属性,它们将在后台调用_load_pascal ...
-
python如何处理递归函数中的返回变量?(How does python treat a returned variable in a recursion function?)[2023-07-07]
你的递归函数有两个分支:如果Bar (不管是什么)不真实,函数会返回一些新节点。 否则,函数以递归方式调用 - 但没有返回值。 因此,如果您希望始终具有一些返回值,则应确保所有代码路径都返回一些值。 例如,您可以从递归函数调用返回值: return FooBar(foo_exp) Your recursive function has two branches: If Bar (whatever that is) is not truthful, the function returns some new ... -
这些应该是两个独立的功能,一个使用另一个。 function costs($date1, $date2, $price) { $cost = days($date1, $date2) * $price; return $cost; } function days($date1, $date2) { $arr= explode("/", $date1); $timestamp1 = mktime(0,0,0,$arr[1],$arr[0],$arr[2]); ...
-
如果你想创建一个类变量,你必须在任何类方法之外声明它(但仍然在类定义中): class Example(object): somevariable = 'class variable' 有了这个,你现在可以访问你的类变量。 >> Example.somevariable 'class variable' 你的例子不工作的原因是你正在给一个instance变量赋值。 两者的区别在于一旦类对象被创建就会创建一个class变量。 而instance变量将在对象实例化后创建,并且只有在分配给对象后才 ...
-
在Python中,一个类的静态变量(实际上是所有属性)总是公开的。 哎呀,Python不区分公共和私人。 隐私只是一个惯例[1] 。 因此,您可以轻松访问Animal name 。 但是,在Ruby中,类变量不能在类之外访问。 他们默认是私人的[2] 。 一切都通过返回变量值的方法来设置[3] 。 所以,如果你想访问类变量,你只需要为你的类创建getter / setter方法[4] 。 如下所示。 class Animal @@hand = 2 def hand @@ha ...
-
这里的问题是您要在subscribe功能之外分配视频网址。 getExercise(){ this.videoService.getExercise(this.exercise_id) .subscribe( exercise => { this.exercise = exercise; console.log(this.exercise[0].video_url) // NEW LINE ...
-
这个例子有点扭曲。 父类的定义不完整,它引用了不存在的类变量,只有在实例化类或对其进行子类化时才会变得明显。 如果你的子类如下: class Child2(Parent): def __init__(self): super(Child2, self).__init__() 然后实例化子类将不起作用: Traceback (most recent call last): File "./cl.py", line 25, in
y=Child2() ... -
闭包的范围基于创建函数的位置。 // It has access to any x in this scope var obj=function(){ // It has access to any x in this scope this.fun=function(){ // It has access to any x in this scope console.log(x); }; }; ...但你在这里定义了X: var data=funct ...