C++
Dovy
这个作者很懒,什么都没留下…
展开
-
ros2 自定义消息
在使用ros2时,有时需要自定义一个数据结构传递数据。具体方法如下## 创建ros2包ros2 pkg create --build-type ament_cmake --node-name box box## 创建msg文件夹,并创建*.msg数据结构cd boxmkdir msgtouch box.msgbox.msg中添加数据结构std_msgs/Header headerint32 xint32 yint32 widthint32 height## 修原创 2021-09-15 17:48:36 · 375 阅读 · 0 评论 -
ubuntu c++时间计算
#include <stdio.h>#include <sys/time.h>#include <unistd.h>class Time{public: Time(){} ~Time(){} void start() { gettimeofday(&tv1,nullptr); } int cost() { gettimeofday(&tv2,nullpt.原创 2021-07-05 17:09:39 · 906 阅读 · 0 评论 -
c++测试题
栈的压入、弹出序列方法:模拟法直接模拟即可。因为弹出之前的值都会先入栈,所以这里用个栈来辅助。#include <vector>#include <stack>#include <iostream>using namespace std;/** * @brief 给出一个入栈序列pushV和出栈序列popV, 判断出栈序列是否满足条件. * @param pushV 栈的压入顺序. * @param popV 是否可能为该栈的弹出顺序.原创 2020-08-12 11:32:15 · 151 阅读 · 0 评论 -
排序比较算法c++
冒泡排序时间复杂度:O(n2)O(n^2)O(n2)#include <stdlib.h>#include <stdio.h>#include <iostream>using namespace std;void bubbleSort(int arr[], int len){ int i, j; for (i = 0; i < len - 1; i++) { for (j = 0; j < len - 1 - i原创 2020-08-07 11:33:26 · 205 阅读 · 0 评论 -
C++STL-ALGORITHM函数
在编写c++代码时,有很多常用方法,在stl algorithm中给出了接口,这里简单介绍部分方法。std::foreach逐个元素传入函数或类实例,执行相应的操作。template<class InputIterator, class Function> Function for_each(InputIterator first, InputIterator last, Function fn){ while (first!=last) { fn (*first);原创 2020-08-03 10:51:59 · 294 阅读 · 0 评论 -
c++注册类方法实现单例映射
概述在caffe和阿里MNN中,广泛使用了注册方法,简化了代码的复杂程度。下面我们简单梳理一下。分析要实现一套多种计算架构使用的代码,如cpu、gpu等。要在每个计算架构下,实现各种算子。使用一套接口实现。要达到以上要求,需要给各部分设置通用的接口,利用c++类的继承,能让所有的计算架构或算子具有相同的接口,接口一致,有利于代码的简化。解析定义通用结构平台typedef enum { MNN_FORWARD_CPU = 0, /* Firtly find原创 2020-06-06 12:20:29 · 698 阅读 · 0 评论 -
c++ 读写float二进制文件
template <typename T>void save_bin_file(std::string file, int size, T *buffer){ std::ofstream ofs(file, std::ios::binary | std::ios::out); if (ofs) { ofs.write((const char ...原创 2020-04-21 14:16:35 · 1229 阅读 · 0 评论 -
非常好的makefile写法
要点makefile的依赖规则,都是从前向后的。即当前依赖的向后找或写在编写makefile时,一定要搞清楚依赖关系。如:.o 依赖的.cpp.so依赖的.o…链接时的依赖关系链接的动态库有依赖关系时,要注意顺序,被依赖的放后面,相互没依赖,随便放。工程文件的组织形式好的文件组织形式,可以使我们的makefile文件更加清晰,写起来更顺心。.d文件很重要配置了.d文件,我...原创 2020-04-20 15:12:50 · 325 阅读 · 0 评论 -
opencv交叉编译linux-aarch64
准备下载opencv源码(官网下载)下载交叉编译器https://releases.linaro.org/components/toolchain/binaries/latest-7/arm-linux-gnueabi/按照宿主机类型(这里以X64 Linux为例)选择下载链接, 文件名形如 gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi...原创 2020-04-14 10:36:25 · 1968 阅读 · 2 评论 -
opencv交叉编译android库
准备下载android-sdkandroid-sdk解压tools 执行 ./android update sdk选择一个build-tools安装android-ndkhttps://developer.android.google.cn/ndk/downloads编译cmake … -DCMAKE_TOOLCHAIN_FILE=…/platforms/android/and...原创 2020-04-27 21:24:17 · 933 阅读 · 0 评论 -
C++常见用法
C++实战技巧类参数初始化在类的使用中,在构造函数后初始化参数,可以给常量赋值。const成员函数不修改成员变量,const实例对象调用时,不会出现限制类型丢失错误。class Test{public: Test() { value = 0; } ~Test() {} int get() const { ret...原创 2020-04-09 12:59:09 · 380 阅读 · 0 评论 -
c++ 单实例
template <class T>class BaseSingleton{private: static T* m_pInstance; class Garbo { public: ~Garbo() { if (BaseSingleton::m_pInstance) ...原创 2020-04-09 13:19:34 · 275 阅读 · 0 评论