C++ function prototypes?

前端 未结 3 1229
粉色の甜心
粉色の甜心 2021-01-21 00:23

Here goes newbie question number 5, but I don\'t have a teacher.. so.. anyhow here we go:

I\'m wondering if is necessary to have function prototypes at the top of the fi

3条回答
  •  天涯浪人
    2021-01-21 01:14

    This declares but does not define the function say_hi:

    void say_hi();
    

    This both declares and defines the function say_hi:

    void say_hi(){
        std::cout << "hi" << std::endl;
    }
    

    You can declare a function many times; you can only define it once.

    A function must be declared in the file before you can call it. A function must be defined somewhere--in the same file before or after you call it or maybe even in a different file.

    So, yes, this is perfectly fine.

提交回复
热议问题