Come up and C++ me some time ~ (chapter 7~11)

本文深入探讨C++中的关键概念,包括const指针转换、模板类array对象使用、函数指针定义、内联函数与宏的区别、引用与指针的不同之处、默认参数规则、函数重载原则、函数模板实现、名字空间应用、类的构造与析构细节以及运算符重载技巧。
Point 1:    const与非const指针相互转换

如果数据类型本身并不是指针,则可以将cosnt数据或非const数据的地址赋给指向cosnt的指针,但只能将非const数据的地址赋给非const指针

Point 2:	C++11模板类array对象

#include<iostream>
#include<array>
const int Seasons= 4;
const std::array<std::string, Seasons>Snames= { "Spring", "Summer", "Fall", "Winter" }; //定义
void fill(std::array<std::string, Seasons> *pa);

Point 3:	函数指针
const double * f1(const double [] , int n); 
const double *(*p1)(const double [] , int n)= f1;

Point 4:	内联函数与宏定义

如果程序在十个地方调用同一个内联函数,则该程序会包含该函数代码的十个副本。

要使用内联函数,需满足以下三种条件之一:

1、在函数声明前加关键字inline

2、在函数定义前加关键字inline

3、在类定义中包含函数体

内联与宏:

	#define SQUARE(X)  ((X)*(X))
	inline SQUARE(X) { return X*X; }

宏不能按值传递,SQUARE(C++)将C递增两次,而内联函数不会。

Point 5:	引用和指针的差别
1、引用是已定义变量的别名,主要用途是用作函数的形参。通过将引用变量作为参数,函数将使用原始数据而不是其副本。

	int rat= 10;
	int &rodent= rat;

2、引用必须定义时初始化且不能初始化后被左值,不能像指针那样先声明后赋值。

3、函数返回引用时不能返回已释放内存单元的引用。

Point 6:	默认参数规则
函数原型中设置默认值

char *left(const char * str, int n= 1);
int harpo(int n, int m= 4, int j= 5);

Point 7:	函数重载规则
函数重载的关键是函数的参数列表,也称为函数特征标。如果两个函数的参数数目和类型相同,同时参数的排列顺序也相同,则他们的特征标相同(与返回值无关)。C++允许定义名称相同的函数,条件是他们的特征标不同。

void  print(int num);
void  print(char *arr);
void  print(double d, int width);

Point 8:	函数模板
template <typename  T>
void  swap(T &a, T &b);

template <typename  T>
void  swap(T *a, T *b, int n);

template <typename  T>
void  swap(T &a, T &b)
{
//......................................
}
template <typename  T>
void  swap(T *a, T *b, int n)
{
//........................................
}

Point 9:	名字空间

1、可传递可嵌套

namespace myth{

using std::cout;

using std::cin;

using namespace elements;   //可包含其他名字空间

}

using namespace myth;

cin.get();

2、统一编程理念

使用在名称空间中声明的变量,而不是使用外部全局变量和静态全局变量

不要在头文件中使用using编译指令,首先这种做法可能掩盖某些可用名称,其次包含头文件的顺序可能影响程序的行为。如果非要使用,也应将其放在所有#include指令之后

对于using声明,首选将其作用域设置为局部而不是全局,别忘了使用命名空间的主旨是简化大型编程项目的管理工作


Point 10:	类的构造、析构、拷贝构造函数、深拷贝、浅拷贝
构造函数:当且仅当没有定义任何构造函数时,编译器才会提供默认构造函数。为类定义了构造函数就必须为其定义提供默认构造函数。

析构函数:对象过期时将调用的函数,如果构造函数或析构函数都私有化则调用不到

拷贝构造函数:类对象之间的赋值将调用的函数,当且仅当没有定义任何拷贝构造函数时,编译器才会提供默认的拷贝构造函数,执行的就是浅拷贝

深拷贝:如果拷贝构造函数中一旦存在动态成员,浅拷贝就会出现问题。而深拷贝时对象中动态成员将动态分配空间从而避免两个变量指向同一块内存

技巧:可以声明私有拷贝构造函数来避免默认拷贝的发生,而不必定义该构造函数。如果用户尝试按值传递或函数返回该对象时将得到一个错误,从而避免按值传递或返回对象

private:  
//拷贝构造,只是声明  
CExample(const CExample& C);  


Point 11:	运算符重载

对于成员重载运算符函数,运算符表达式中形参为运算符右边的操作数

Time  Time::operator + (const Time &t) const;

Time  Time::operator - (const Time &t) const;

Time  Time::operator * (double mult) const;

对于非成员重载运算符函数,运算符表达式左边的操作数对于运算符参数的第一个形参,右边的操作数对于第二个形参

Time  operator* (double mult, const Time &t );

【SCI一区复现】基于配电网韧性提升的应急移动电源预配置和动态调度()—MPS动态调度(Matlab代码实现)内容概要:本文档围绕“基于配电网韧性提升的应急移动电源预配置和动态调度”主题,重点介绍MPS(Mobile Power Sources)动态调度的Matlab代码实现,是SCI一区论文复现的技术资料。内容涵盖在灾害或故障等极端场景下,如何通过优化算法对应急移动电源进行科学调度,以提升配电网在突发事件中的恢复能力与供电可靠性。文档强调采用先进的智能优化算法进行建模求解,并结合IEEE标准测试系统(如IEEE33节点)进行仿真验证,具有较强的学术前沿性和工程应用价值。; 适合人群:具备电力系统基础知识和Matlab编程能力,从事电力系统优化、配电网韧性、应急电源调度等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于复现高水平期刊(SCI一区、IEEE顶刊)中关于配电网韧性与移动电源调度的研究成果;②支撑科研项目中的模型构建与算法开发,提升配电网在故障后的快速恢复能力;③为电力系统应急调度策略提供仿真工具与技术参考。; 阅读建议:建议结合前篇“MPS预配置”内容系统学习,重点关注动态调度模型的数学建模、目标函数设计与Matlab代码实现细节,建议配合YALMIP等优化工具包进行仿真实验,并参考文中提供的网盘资源获取完整代码与数据。
### YOLOv11 C++ Implementation on Rockchip RK3688 Platform For implementing YOLOv11 using C++ on the Rockchip RK3688 platform, several considerations and steps need to be addressed based on previous experiences with similar platforms like RK3368 running Android 9.0[^1]. The development process involves setting up an appropriate environment that supports hardware acceleration through libraries compatible with the Rockchip architecture. #### Setting Up Development Environment To begin developing a C++ application for object detection using YOLOv11: - Ensure the target device runs a suitable version of Android or Linux operating system. - Install necessary build tools such as NDK (Native Development Kit), which is essential when working within the Android ecosystem[^2]. - Utilize pre-built binaries or compile from source frameworks supporting neural network inference optimized for ARM architectures including TensorFlow Lite, NCNN, MNN among others. #### Hardware Acceleration Support Rockchip SoCs come equipped with dedicated GPUs and NPUs designed specifically for accelerating machine learning tasks. Leveraging these components requires integrating APIs provided by Rockchip into your project. For instance, rknn_api can facilitate loading models onto the NPU efficiently while handling data preprocessing/postprocessing operations effectively[^3]. ```cpp #include "rknn_api.h" // Initialize model context rknn_context ctx; int ret = rknn_init(&ctx, "./yolov11.rknn", 0, 0, NULL); if(ret < 0){ printf("Failed to init rknn\n"); } ``` This code snippet demonstrates initializing a `.rknn` file containing the compiled YOLOv11 model ready for deployment on devices featuring Rockchip processors. #### Integrating YOLOv11 Model Once the environment has been configured properly along with access granted towards utilizing onboard accelerators, focus shifts toward incorporating the actual deep learning algorithm itself. This typically entails converting pretrained weights obtained elsewhere into formats supported natively by chosen runtime environments before deploying them accordingly. The conversion step may involve scripts transforming PyTorch/TensorFlow checkpoints into ONNX representations followed by further processing via vendor-specific toolchains resulting ultimately in deployable artifacts tailored explicitly for execution atop selected silicon solutions offered under the Rockchip banner. --related questions-- 1. What are some key differences between HIDL and AIDL interfaces used across various versions of Android? 2. How does one go about optimizing performance metrics associated with real-time object recognition applications leveraging embedded systems' capabilities? 3. Can you provide guidance regarding best practices concerning memory management during intensive computational workloads involving AI algorithms executed directly upon mobile-grade SOCs?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值