惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
小众软件
小众软件
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 【当耐特】
爱范儿
爱范儿
博客园 - 聂微东
美团技术团队
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
有赞技术团队
有赞技术团队
云风的 BLOG
云风的 BLOG
罗磊的独立博客
V
Visual Studio Blog
WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
V
V2EX
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

博客园 - 于光远

泛型编程 分区理论知识整理 SPI协议及驱动开发框架 I2C协议及驱动开发框架 使用qemu 加载linux-6.18.1内核 linux 内核 策略模式 单例模式 Linux性能分析:从监控到优化的完整工具链 C++模板元编程实现序列化与反序列化 引用 bootchart linux 脚本打印时间 不定参数解析,结合tuple 独立于main运行的程序 类模板继承 std::ostream & operator<< Flash HIDL --HelloWorld
接口编程
于光远 · 2022-07-14 · via 博客园 - 于光远

App调用接口,依赖头文件和库。

库文件更新,App代码不需要重新编译,直接就可以运行。

//main.cpp

//main.cpp

#include "IStudent.h"

int main(){

getIStudent()->TellStory();

}

//IStudent.h
//
#pragma once #ifndef IS_H #define IS_H #include <iostream> class IStudent { public: IStudent(){} virtual ~IStudent(){} virtual void TellStory() = 0; }; IStudent* getIStudent(); void test(); #endif
//Student.h
//#pragma once
#ifndef S_H
#define S_H

#include "IStudent.h"
#include <iostream>

class Student: public IStudent
{
private:
    /* data */
public:
    Student(/* args */);
    ~Student();
    void TellStory();
};

 #endif
//Student.cpp
#include "Student.h"
#include <iostream>

void Student::TellStory(){
    std::cout<<"hello world"<<std::endl;
 }

Student::Student(/* args */)
{
}

Student::~Student()
{
}

void test(){std::cout<<"ss222ss"<<std::endl;}

 IStudent*  getIStudent(){
    IStudent* I = new Student();
    return I;
 }

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)
project(student)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

add_library(Istudent SHARED Student.cpp)

#set(SOURCE_FILES main.cpp)
#add_executable(student ${SOURCE_FILES})

#target_link_libraries(student Istudent)

先全编译,生成库和可执行程序。

然后不需要再编译可执行程序了,修改Student.cpp 的打印。编译生成新的库文件

运行可执行程序。可执行程序可以打印新的更改。