在C ++中的原型 [英] Prototyping in C++
问题描述
如果我在我的代码中的主函数上面的函数原型,我必须包括所有必须给出的参数吗?有没有办法我怎么能只是原型的功能,节省时间,空间和内存?
If I prototype a function above the main function in my code, do I have to include all parameters which have to be given? Is there a way how I can just prototype only the function, to save time, space and memory?
这里是我想出这个问题的代码:
Here is the code where I came up with this question:
#include <iostream>
using namespace std;
int allesinsekunden(int, int, int);
int main(){
int stunden, minuten, sekunden;
cout << "Stunden? \n";
cin >> stunden;
cout << "Minuten? \n";
cin >> minuten;
cout << "Sekunden= \n";
cin >> sekunden;
cout << "Alles in Sekunden= " << allesinsekunden(stunden, minuten, sekunden) << endl;
}
int allesinsekunden (int h, int m, int s) {
int sec;
sec=h*3600 + m*60 + s;
return sec;
}
推荐答案
$ b如果我在我的代码中对main函数进行原型化,那么是否必须包含所有必须提供的参数?
是,否则编译器不知道您的函数是如何被调用的。
函数可以在c ++中重载,这意味着函数相同名称可以具有不同数量和类型的参数。这样的名字本身就不够清楚。
Yes, otherwise the compiler doesn't know how your function is allowed to be called.
Functions can be overloaded in c++, which means functions with the same name may have different number and type of parameters. Such the name alone isn't distinct enough.
有没有办法我只能原型只有函数,节省时间,空间和记忆?
"Is there a way how I can just prototype only the function, to save time, space and memory?"
你为什么认为会节省任何记忆?
No. Why do you think it would save any memory?
这篇关于在C ++中的原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!