![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
文章平均质量分 80
keineahnung2345
这个作者很懒,什么都没留下…
展开
-
Linux(docker)下使用VSCode運行C++專案
在網上找過一些使用VSCode運行C++專案的文章,發現大多數文章起手就是launch.json,settings.json和tasks.json。但如果只想編譯現成的C++專案,可以不用這麼複雜,基本上按照官方教學來做即可。原创 2021-10-15 22:44:42 · 1157 阅读 · 0 评论 -
C++ typename使用時機
PCL中的surface/include/pcl/surface/mls.h裡宣告的pcl::MovingLeastSquares類別有這麼一段代碼:觀察KdTree和KdTreePtr,可以發現一個沒加,另一個則有加typename。他們之間的區別詳見下文。原创 2021-08-28 23:49:56 · 148 阅读 · 0 评论 -
C++ using - 繼承共同行為 & 改變成員的訪問權限
PCL中的surface/include/pcl/surface/mls.h裡宣告的pcl::MovingLeastSquares類別有這麼一段代碼:這邊的using有:繼承共同行為改變成員的訪問權限兩種作用,詳見下文。原创 2021-08-28 22:24:38 · 582 阅读 · 0 评论 -
.template cast<>中template的作用
PCL中的surface/include/pcl/surface/impl/mls.hpp裡有這麼一段代碼:query_point = cloud[index].getVector3fMap ().template cast ();第一次看到.template cast這種寫法一定覺得不明所以,本篇的目的就是要探討template關鍵字在此處的作用。原创 2021-08-28 10:20:28 · 1545 阅读 · 1 评论 -
Windows 10下安裝OpenSSL 1.1.1
OpenSSL官網為OpenSSL,可以從上面下載openssl-1.1.1k.tar.gz後按照NOTES-WINDOWS.md的說明手動編譯安裝。但是看起來OpenSSL的依賴並不少,自己編譯可能會很麻煩,所以這裡直接使用installer來安裝。原创 2021-07-29 16:07:25 · 7445 阅读 · 2 评论 -
Windows 10及Visual Studio 2015下安裝libconfig
筆者一開始打算在Windows 10下安裝官方的libconfig,並搭配Visual Studio 2015使用。但是因為官方的教程在這方面並沒有太多著墨,筆者自己踩了坑後(詳見Unable to compile on Windows 10),決定轉而使用vcpkg來安裝。原创 2020-07-10 14:13:58 · 1244 阅读 · 1 评论 -
c++11 std::unique_ptr error cmake 3.11.3 bootstrap
前言這是在按照How do I install the latest version of cmake from the command line?安裝cmake時,其中一步./bootstrap所報的錯。筆者是在VirtualBox裡的Ubuntu 16.04下安裝的,cmake根目錄放在mounted directory,才導致了這個錯誤:------------------------...原创 2020-04-19 22:02:16 · 1801 阅读 · 0 评论 -
C++ new的使用場景
C++ new的使用場景TensorRT中的例子參考連結C++中我們可以使用如:Classname myobj;或:Classname* myptr = new Classname;兩種方式來創建物件,它們的差別在哪呢?詳見下表:不使用new使用newmemory areastackfree store(heap)是否需要使用delete銷毀否是...原创 2020-02-15 20:28:11 · 438 阅读 · 0 评论 -
C++ delete this
C++ delete this前言can only be used with newaccess member variable after delete this參考連結前言本篇基於“delete this” in C++,並完善了原文中提供的幾個例子。can only be used with new只有當物件是使用new創建的,我們才能使用delete this來銷毀它。定義一個名...原创 2020-02-15 09:05:51 · 383 阅读 · 0 评论 -
C++ google protobuf
C++ google protobuf前言google::protobufgoogle::protobuf::io::ZeroCopyInputStreamgoogle::protobuf::io::IstreamInputStreamgoogle::protobuf::io::CodedInputStreamSetTotalBytesLimitgoogle::protobuf::io::Arra...原创 2020-02-10 18:53:08 · 2532 阅读 · 0 评论 -
C++ ifstream
C++ ifstreamstd::ifstreamconstructorcheck statuscloseTensorRT中的例子參考連結std::ifstream參考std::ifstream:Input stream class to operate on files.Objects of this class maintain a filebuf object as their i...原创 2020-02-10 12:20:05 · 1799 阅读 · 0 评论 -
Protocol Buffer(proto2)及C++ API
Protocol Buffer(proto2)及C++ API前言Protocol BufferProtobuf語法packagescalar value typesmessagerequired, optional, repeatedenum編譯C++ protocol buffer APIenumnested classStandard Message MethodsParsing and S...原创 2020-02-09 23:23:27 · 1283 阅读 · 0 评论 -
C++ Explicitly defaulted function
C++ Explicitly defaulted function前言Explicitly defaulted functionSpecial member function= default v.s. {}在TensorRT中的例子參考連結前言本篇基於Explicitly Defaulted and Deleted Functions in C++ 11,並加上TensorRT中的例子做為參...原创 2020-02-09 13:44:18 · 1374 阅读 · 0 评论 -
C++ Overload []
C++ Overload []前言Overload []return by referenceTensorRT中的例子參考連結前言本篇基於Overloading Subscript or array index operator [] in C++,並加上TensorRT中的例子做為參考。Overload []以下例子定義了一個類別Array,並對[]這個運算子做overload,使它在進...原创 2020-02-08 21:48:05 · 415 阅读 · 0 评论 -
C++ NULL v.s. nullptr
C++ NULL v.s. nullptrNULLnullptr參考連結NULL摘自Bjarne Stroustrup’s C++ Style and Technique FAQ:In C++, the definition of NULL is 0.即在C++中,NULL與0是沒有區別的。這會造成什麼問題呢?設想以下例子,改自NULL vs nullptr (Why was it r...原创 2020-02-08 20:17:21 · 200 阅读 · 0 评论 -
C++ Overload stream insertion operator and stream extraction operator
C++ Overload << and >>前言Overload << and >>Overload as global functionTensorRT中的例子參考連結前言本篇基於Overloading stream insertion (<>) operators in C++,並加上TensorRT中的例子做為參考。Overl...原创 2020-02-07 14:07:57 · 924 阅读 · 0 评论 -
C++ const_cast
C++ const_castconst_cast簡介與C寫法的比較修改const變數TensorRT中的例子參考連結const_cast簡介const_cast只能作用於指標上,它的作用是為指標去除或加上const或volatile關鍵字。如果我們嘗試將它作用於變數上,則會出現以下錯誤:error: const_cast to 'int', which is not a referenc...原创 2020-02-05 17:31:07 · 493 阅读 · 0 评论 -
C++ std::numeric_limits<T>::max(),min()及lowest()
@[TOC](C++ std::numeric_limits::max(),min()及lowest())std::numeric_limits<T>::max(),min()及lowest()根據std::numeric_limits,如果T屬於浮點數,則:std::numeric_limits<T>::max()回傳該型別的最大值std::numeric_li...原创 2020-02-05 12:45:22 · 6544 阅读 · 0 评论 -
C++ std::isnan及std::isinf
C++ std::isnan及std::isinfstd::isnan及std::isinf參考連結std::isnan及std::isinf摘自isnan,isnan函數的簽名為:bool isnan (float x);bool isnan (double x);bool isnan (long double x);它的作用為:Returns whether x is a Na...原创 2020-02-05 12:44:31 · 3261 阅读 · 0 评论 -
C++ uniform_real_distribution及normal_distribution
C++ uniform_real_distribution及normal_distributionstd::uniform\_real_distributionstd::normal_distribution參考連結std::uniform_real_distributionstd::uniform_int_distribution用於從均勻分布中生成隨機的整數;與它相對,std::unifo...原创 2020-02-03 21:43:15 · 7615 阅读 · 0 评论 -
C++ reinterpret_cast
C++ reinterpret_castreinterpret_cast參考連結reinterpret_castreinterpret_cast用於將某種類型的指標強行轉換為另一種類型的指標。因為它不會做類型檢查,所以與static_cast比起來,它是較為危險的。在TensorRT/blob/master/samples/common/common.h的函數readPGMFile中:in...原创 2020-01-30 16:32:47 · 428 阅读 · 0 评论 -
PGM檔案格式
PGM檔案格式PGM檔案格式參考連結PGM檔案格式PGM全文Portable Gray Map,是一種圖片檔案格式。PGM圖像包含了以下幾個元素:一個magic number,代表檔案格式。PGM圖片的magic number是"P5"這兩個字元。空白符(空格,tab,CR,LF)寬度(W),用ASCII字元表示空白符高度(H),用ASCII字元表示空白符最大灰度值(Maxva...原创 2020-01-30 15:52:34 · 563 阅读 · 0 评论 -
C++ lambda expression
C++ lambda expressionlambda expression參考連結lambda expressionC++11引入了lambda expression,用於定義無名的函數。其語法為:[ capture clause ] (parameters) -> return-type { definition of method } capture ...原创 2020-01-29 23:45:16 · 193 阅读 · 0 评论 -
C++ RAII(Resource Acquisition Is Initialization)
C++ RAII(Resource Acquisition Is Initialization)RAII(Resource Acquisition Is Initialization)參考連結RAII(Resource Acquisition Is Initialization)RAII,即"資源獲取即初始化"。或許換個稱呼會比較好理解:Scope-Bound Resource Managem...原创 2020-01-28 17:43:02 · 292 阅读 · 0 评论 -
C++ emplace_back
C++ emplace_backemplace_back參考連結emplace_back在C++11之前,我們只有std::vector::push_back,因此我們得先創建一個temporary object,然後呼叫push_back把它放入(實際上是複製)vector裡。C++11引入了std::vector::emplace_back,它可以接受其元素的constructor的參數...原创 2020-01-26 20:28:26 · 524 阅读 · 0 评论 -
C++ static_cast
C++ static_cast型別轉換:C v.s. C++static_cast參考連結型別轉換:C v.s. C++C語言裡的型別轉換在C++中被分成了 static_cast, dynamic_cast, const_cast 及reinterpret_cast等四種不同的方式,這是為了確保在不同的情況下,型別轉換的代碼都能work as expected。static_cast根據...原创 2020-01-26 18:07:24 · 1087 阅读 · 0 评论 -
C++ const member function
C++ const member functionconst member function參考連結const member function在函數定義後面加上const就成了const member function,它的作用是確保在函數裡面不會有成員變數被意外地修改。在const member function內,如果嘗試去修改任一成員變數,都會造成編譯錯誤。另外注意:一個const o...原创 2020-01-25 09:51:37 · 2380 阅读 · 0 评论 -
C++ functor
C++ functorfunctor參考連結functor假想有一個函數的功能是將傳進來的參數加一之後回傳:int add_one(int x){ return x + 1;}如果我們想把該函數的功能改為加二,一種方法是再定義一個同樣的函數,但是把加一改成加二:int add_two(int x){ return x + 2;}雖然上面這種方法也能達到目的,但總...原创 2020-01-25 09:37:12 · 1084 阅读 · 0 评论 -
C++ smart pointer,unique_ptr,shared_ptr
C++ smart pointer,unique_ptr,shared_ptrsmart pointerstd::unique_ptrstd::shared_ptr參考連結smart pointer與一般的pointer相比,smart pointer的優勢在於我們不需要顯式地呼叫delete(ptr)來釋放它所佔用的記憶體。只要smart pointer一落在可視範圍之外,smart poi...原创 2020-01-25 07:37:16 · 1894 阅读 · 0 评论 -
C++ typedef struct v.s. struct
C++ typedef struct v.s. structtypedef struct v.s. struct參考連結typedef struct v.s. struct在C語言中,定義完一個struct之後,我們通常還會加上typedef。這樣以後用到struct xxx時,我們就能用yyy代指,而不用老是加上struct這個關鍵字:struct xxx {...};typedef s...原创 2020-01-24 19:04:30 · 294 阅读 · 0 评论 -
C++ struct初始化
C++ struct初始化struct初始化參考連結struct初始化摘自C++ Structure Initialization:The field identifiers are indeed C initializer syntax. In C++ just give the values in the correct order without the field names. ...原创 2020-01-24 17:21:18 · 5909 阅读 · 0 评论 -
C++ struct的繼承
C++ struct的繼承struct的繼承參考連結struct的繼承參考自Structure vs class in C++:When deriving a struct from a class/struct, default access-specifier for a base class/struct is public. And when deriving a class, de...原创 2020-01-23 22:11:48 · 316 阅读 · 0 评论 -
C++ namespace,extending namespace
C++ namespacenamespace參考連結namespace一個變數或函數默認是全局可見的(global scope);如果我們在一個命名空間裡定義函數或變數,那麼它們便只於該命名空間中可見(namespace scope),也因此在不同命名空間裡定義相同名字的變數是合法的。來自TensorRT/samples/common/argsParser.h,關於命名空間samplesCo...原创 2020-01-23 22:06:15 · 293 阅读 · 0 评论 -
TensorRT/samples/common/logger.h,logger.cpp,logging.h源碼研讀
TensorRT/samples/common/logger.h,logger.cpp,logging.h源碼研讀前言logger.hlogger.cpplogging.hexternlist initializationusingmember initializer listmove constructortime_t, tm多重繼承的順序(純)虛擬函數nested classfriend cl...原创 2020-01-23 21:36:56 · 1771 阅读 · 0 评论 -
C++ translation unit & anonymous namespace(unnamed namespace)
C++ translation unit & anonymous namespace(unnamed namespace)translation unitanonymous namespace(unnamed namespace)參考連結translation unit在進入unnamed namespace前,必須先有translation unit的概念。以下段落摘自What is...原创 2020-01-23 18:06:02 · 499 阅读 · 0 评论 -
C++ inline function
C++ inline functioninline function參考連結inline function在呼叫函數時,會將控制權由caller傳給callee,也會進行一些必要的資源分配,即overhead。如果這段事前準備的時間比callee的執行時間比還長,那麼呼叫函數明顯就是不划算的。為了避免這種情況發生,我們可以將函數定義為inline function。如此一來,編譯器便會(選...原创 2020-01-23 17:28:10 · 332 阅读 · 0 评论 -
C++ EXIT_SUCCESS, EXIT_FAILURE
C++ EXIT_SUCCESS, EXIT_FAILUREEXIT\_SUCCESS, EXIT_FAILURE參考連結EXIT_SUCCESS, EXIT_FAILURE這兩個macro定義於C語言的<stdlib.h>(或C++的<cstdlib>):#define EXIT_SUCCESS /*implementation defined*/#define ...原创 2020-01-23 16:54:56 · 780 阅读 · 0 评论 -
C++ assert(0)
@[TOC](C++ assert(0))assert(0)在TensorRT/samples/common/logging.h的LogStreamConsumer:: severityPrefix中使用了assert(0):class LogStreamConsumer : protected LogStreamConsumerBase, public std::ostream{//....原创 2020-01-23 16:25:18 · 812 阅读 · 0 评论 -
C++ enum class
C++ enum classenum class參考連結enum class相較於enum type,C++11引入的enum class有著strongly typed及strongly scoped的優點。TensorRT/samples/common/logging.h中定義了一個enum class TestResult:enum class TestResult{ kR...原创 2020-01-23 16:05:33 · 226 阅读 · 0 评论 -
C++ (opaque) handle
C++ (opaque) handlehandleopaque handle參考連結handleHandle是一個指標或索引,被用來存取某項資源。範例可以參考What is a handle in C++? - jmucchiello。opaque handleOpaque handle則是一個在定義時看不到它的內容的一種handle。詳見Opaque Pointer。在TensorRT...原创 2020-01-23 15:44:26 · 652 阅读 · 0 评论