函数功能点实战

函数的四种形式
函数定义和声明分开
函数分离式编译
函数重载
函数传递引用
内联函数
静态变量
sub01.h
#ifndef MYTEST_SUB01_H
#define MYTEST_SUB01_H

void sub1(int a,int b);


#endif //MYTEST_SUB01_H

sub01.cpp

#include <iostream>
#include "sub01.h"
using namespace std;

void sub1(int a,int b){
    cout << a + b << endl;
}
function.cpp


#include <iostream>
#include <string>
#include "sub01.h"


using namespace std;

//函数的四种形式
// 无参无返回值
void goodMorning(){
    cout << "goodmoring"<< endl;
}

// 无参有返回值
string say_hi(){
    return "hi";
}

// 有参无返回值
void sayhello(string name){
    cout << "hello" << name << endl;
}

// 有参有返回值
string nice(string name){
    return "nice you" + name;
}

// 函数定义和声明分开
string getName(string name);

//函数分离式编译

// 函数重载
int add(int a,int b){
    return a + b;
}

int add(int a,int b,int c){
    return a + b + c;
}

int add(int a,double b){
    return a +b;
}

// 函数传递引用
void getScore(int &score){
    score = 100;
}

// 内联函数
inline int compare(int a,int b){
    if(a > b){
        return a;
    }
    return b;
}

//静态变量
void static_num(){
    static int num =100;
    num += 1;
    cout << num<< endl;
}

int main(){
    goodMorning();
    string result1 = say_hi();
    cout << result1 << endl;
    sayhello("xiaohong");
    string result2 = nice("xiaomli");
    cout << result2 << endl;

    string name = getName("xiaoming");
    cout << name << endl;

    sub1(1,2);

    add(1,2);
    add(1,2,3);
    add(1,1.3);

    int a = 10;
    getScore(a);
    cout << a << endl;

    compare(1,2);
    static_num();
    static_num();
}

string getName(string name){
    return name;
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值