什么是C++中的'C-like'模块?以及如何实施它?

what is a 'C-like' module in C++? and how to implement it?

本文关键字:何实施 C-like C++ 中的 什么 模块      更新时间:2024-05-09

我是C++的新手,有一项任务需要在类C模块中完成。根据我的教授,"类C"模块没有正在编写的类,只有一个非成员(类C(函数。我的任务是编写一个C风格的模块排序;在.h文件中使用函数sort((对.cpp进行排序。sort((接受一个整数数组,并使用冒泡排序对数组进行排序。如果不涉及类,我该如何实现?

在C++语言中,您可以在类的外部拥有函数,称为独立函数。

分拣时间:

#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语言不支持类和成员函数。