在C ++中的原型 [英] Prototyping in C++

查看:184
本文介绍了在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆