我在IonizationTunnel.h文件中遇到了这个被重写的函数调用操作符():
void operator()(Particles *, std::vector<double>*, unsigned int, int ipart_ref = 0) override;
这与Ionization.h文件中的虚拟void运算符()的参数完全匹配:
virtual void operator()(Particles *, std::vector<double>*, unsigned int, int ipart_ref = 0) {}
电离是基类。IonizationTunnel是派生类。
2个问题:
我见惯了foo(int x){code},从来没有见过foo(int){code}。
非常感谢!
一个不一定需要名称的未使用参数有时对于让重载解析选择所需的重载很有用:
void foo(int) {
std::cout << "this is foo(int)\n";
std::cout << "I dont need a name for the argument, because I am not using it anyhow";
}
void foo(double) {
std::cout << "this is foo(double)";
}
foo(1); // calls foo(int)
foo(1.0); // calls foo(double)
但是,您看到的可能只是声明中省略的名称,而在定义中它们将被命名,如:
void foo(int); // forward declaration
void bar(int x) {
if (x==42) foo(x); // needs a declaration of foo
}
void foo(int x) { // definition
if (x!=42) bar(x);
}
=something
是默认参数。一个函数
void foo(int x = 0) {
std::cout << x;
}
可以这样调用:
foo(42);
或者像这样:
foo();
在这种情况下,它相当于调用
foo(0);