c++ - 什么是 C++ 中的“类 C”模块?以及如何实施?
问题描述
我是 C++ 新手,我有一个任务需要在 C 类模块中完成。根据我的教授的说法,“类 C”模块没有编写任何类,只有一个非成员(类 C)函数。我的任务是在 .h 文件中编写一个带有函数 sort() 的 C 风格模块 sort.h 和 sort.cpp。sort() 接受一个整数数组并使用冒泡排序对数组进行排序。如果不涉及课程,我该如何实现?
解决方案
在 C++ 语言中,您可以拥有类之外的函数,称为独立函数。
排序.hpp:
#ifndef SORT_HPP
#define SORT_HPP
#include <vector>
void my_sort(std::vector& v);
#endif
排序.cpp:
#include "sort.hpp"
void my_sort(std::vector& v)
{
// Insert code to sort the vector here.
}
它是一个类 C 模块,因为 C 语言不支持类和成员函数。
推荐阅读
- java - 集成集成与基座的宏扩展错误
- tensorflow - 有没有办法将 WebGL tensorflow 后端与 Mali T720(三星 Tab E)一起使用?
- wordpress - 如何在woocommerce中的排序选项之前添加文本
- python - 在一张图中同时绘制两个横截面强度
- sql - 如果在 Postgresql 中使用 select 语句
- arrays - 如何使我的数组列在 numpy 上统一?
- javascript - 如何通过多个标签过滤 JSON 中的数组
- react-native - 还原 | 如何正确连接到 redux 商店
- c# - 如何解决 C# 中的 HRESULT: 0x80010001 (RPC_E_CALL_REJECTED):Excel 互操作?
- angular - 有没有办法在没有 HTML/用户输入的情况下从 Angular 的本地网络中检索 CSV 文件