[C++笔记]02|functions in C++

[note 1]

An example of call by reference

#include <iostream>
using namespace std;
void func(int&a)
{
    cout<<"in func------"<<++a<<endl;
}
int main(int argc, const char * argv[]) {
    int m=1;
    cout<<"m-----1  "<<m<<endl;
    func(m);
    func(2);     //illegal
    cout<<"m-----2  "<<m<<endl;
    return 0;
}

output:

m-----1  1
in func------2
m-----2  2

[note 2]

function overloading

  • if the conversion is possible to have multiple matches, then the compiler will generate an error message.
    [example]
 long square(long n);
 double square(double n);
 square(10);         //will generate an error
发布了51 篇原创文章 · 获赞 5 · 访问量 4210

猜你喜欢

转载自blog.csdn.net/qq_43519498/article/details/91454980