Effective C++ 3nd 读书摘要(六、继承与面向对象设计)Item32 - 40

在Mac上搭建本地AI工作流:Dify与DeepSeek的完美结合 本文介绍了在Mac上搭建本地AI工作流的方法,结合Dify平台和DeepSeek模型。Dify是一个开源的大语言模型应用开发平台,支持可视化AI应用开发。部署步骤包括:1)安装Homebrew和Docker;2)克隆Dify代码库;3)配置环境变量并启动服务。同时,使用Ollama工具本地部署DeepSeek模型,将其集成到Dify中创建聊天助手。通过配置模型接口和新建应用,用户可以在本地环境中实现AI对话功能。这种方案既保证了数据隐私,又提供了灵活的AI应用开发能力。 阅读详情

六、继承与面向对象设计
Item32. 确定你的public继承塑模出is-a关系
(即Liskov Substitution Principle)
下面是一个不严谨的public继承:

Penguin并不会飞。
所以一个较好的替代方案是:

好的设计应该让违反这种关系的继承在编译期间就被检测出来。
public继承主张:能够施行于base class对象身上的_每件事情_都可以施行于derived class对象身上。

 

Item33. 避免遮掩继承而来的名称
C++会遮掩外层的函数名称,而不论它们的参数类型相同与否,也不管这些函数是否是虚函数。(public继承

一定不要让其发生!)


使用using声明可以解决这个问题:

但是using声明式会使某一名称的函数在derived class中全部可见(如上例中,using Base::mf3会使其两个版本都可见)。这在public继承中是正确的(因为它是is-a关系),但在private继承中,可能会只想继承其中某一个版本(如那个无参数版本)。则需要下面的转交技术:

 

Item34. 区分接口继承和实现继承
在设计上可以让一个要被继承的纯虚函数(如fly)同时体现出两个基本要素:
其声明部分表现的是接口(那是derived classes必须使用的),其定义部分则表现出缺省行为(那是derived classes可能使用的,但只有在它们明确提出申请时才是):

小结:pure virtual函数只具体指定接口继承,impure virtual函数具体指定接口继承及缺省实现继承(这样的函数没有不变性,随derived classes而变),non-virtual函数具体指定接口继承以及强制性实现继承(这样的函数没有特化的空间,只能是base class中的那个)。

 

Item35. 考虑virtual函数以外的其他选择
1.籍由Non-Virtual Interface(NVI)实现Template Method模式
源自一个流派,他们主张virtual函数应该几乎总是private。

即-令客户通过public non-virtual成员函数间接调用private virtual。
NVI的一个优点是do "before" stuff和do "after" stuff。这确保得以在一个virtual函数被调用之前设计好适当场景(locking a mutex、log extry、verifying that class invariants and function preconditions are satisfied, etc.),并在调用结束之后清理场景(unlocking a mutex、verifying function postconditions、reverifying class invariants, etc.)。

 

2.籍由Function Pointers实现Strategy模式

这样便得同一人物类型之不同实体可以有不同的健康计算函数。例如:

而且可以在运行期变更计算函数。但是其缺点是当这个传入的non-member函数需要访问class的non-public成分时,我们只能弱化class的封装(如设置为friend、提供public访问函数)。

 

3.籍由tr1::function完成Strategy模式

签名式std::tr1::function<int (const GameCharacter&)>的含义是:接受一个reference指向const

GameCharacter,并返回int。tr1::function产生的对象可以持有任何与此签名式兼容的可调用物。

 

tr1::function比function pointer拥有更大的弹性,下面是三种情况:

①函数
short calcHealth(const GameCharacter&);           // health calculation function;
              //note non-int return type
②函数对象
struct HealthCalculator {                                    // class for health
  int operator()(const GameCharacter&) const     // calculation function
  { ... }                                 // objects
};
③成员函数
class GameLevel {
public:
  float health(const GameCharacter&) const;      // health calculation
  ...                                          // mem function; note
};                                               // non-int return type
定义一些使用者
class EvilBadGuy: public GameCharacter {         // as before
  ...
};
class EyeCandyCharacter:   public GameCharacter {  // another character
  ...                                              // type; assume same
};                                                 // constructor as EvilBadGuy
三种使用方法
EvilBadGuy ebg1(calcHealth);                       // character using a
                                                       // health calculation function
EyeCandyCharacter ecc1(HealthCalculator());        // character using a
                                                  // health calculation function object
GameLevel currentLevel;
...
EvilBadGuy ebg2(                                            // character using a
  std::tr1::bind(&GameLevel::health,               // health calculation
          currentLevel,                                         // member function;
          _1)                                                          // see below for details
);
(将currentLevel绑定为GameLevel对象,_1表示当为ebg2调用GameLevel::health时系以currentLevel作为GameLevel对象)

4.古典的Strategy模式

 

Item36. 绝不重新定义继承而来的non-virtual函数
如果A继承自B,又override了它的non-virtual函数,则此函数被调用时,可能表现出B或A的行为,这得看指

向该对象之指针的声明类型,因为non-virtual函数是statically bound。

 

Item37. 绝不重新定义继承而来的缺省参数值
因为缺省参数值都是静态绑定,而virtual函数却是动态绑定。违反了此条款,就导致调用一个定义于derived

class内的virtual函数的同时,却使用base class为它所指定的缺省参数值。


这时可以考虑替代设计,如NVI:

 

Item38. 通过composition塑模出has-a或is-implemented-in-terms-of
比如你想通过在底层使用list来构造一个set:
template<typename T>                       // the wrong way to use list for Set
class Set: public std::list<T> { ... };

但这种public继承违反了is-a的含义,list中可以有重复元素,但set不可以有,因此set不是一个list。

正确做法是set object can be implemented in terms of a list object:

 

Item39. 明智而审慎地使用private继承
由private继承而来的所有成员,在derived class中都会变成private属性。因此它们都成了实现的枝节。private继承意味着implemented-in-terms-of,这纯粹只是一种实现技术,在软件“设计”层面上没有意义,只在软件实现层面上有意义。

 

如果让class D以private继承class B,含义是为了采用B中已经备妥的某些特性,而不是因为B和D存在有任何观念上的关系。

 

Item38指出composition也用于实现implemented-in-terms-of,但要尽可能使用复合,必要时才使用private继承。

 

例如一个private继承:

也可以换成composition的设计:

composition的设计有两个优点:
1. 使得Widget可以拥有derived classes,但同时又可以阻止derived classes重新定义onTick。这一点private继承无法做到。(此法可用于模拟Java中的final或C#中的sealed)


2. 可以将Widget的编译依存性降至最低。即使WidgetTimer移出Widget体外,也只需要一个class

WidgetTimer声明式,而不用#include WidgetTimer,这是private继承所无法避免的。

 

Private继承有一个优点:可以实现EBO(empty base optimization)。
比较以下,先是composition:

将会发现sizeof(HoldsAnInt) > sizeof(int);
而在private中:

几乎可以肯定:sizeof(HoldsAnInt) == sizeof(int)

另外,当derived class需要访问protected base class的成员,或者需要重新定义继承而来的virtual函数时,使用private设计是合理的。

 

Item40. 明智而审慎地使用多重继承
为了避免钻石型继承,应该对直接继承自顶层的classes采用virtual继承:

class File { ... };
class InputFile: virtual public File { ... };
class OutputFile: virtual public File { ... };
class IOFile: public InputFile, public OutputFile { ... };

 

(thy:virtual继承专为多重继承引入,如果不是virtual继承的话那么如下:

则d.f(); 调用的是B::f(); 如果C,B不是virtual public A的话那d.f()就必须指出f()是类C的还是类D的,d.B::f()或d.C::f())

 

但是virtual继承会比non-virtual继承体积大,访问成员速度慢。另外virtual base的初始化责任是由继承体系中的最低层(most derived)class负责,这意味着若classes派生自virtual bases而需要初始化,它必须认知virtual bases——不论距离多远。

所以 1.非必要不使用virtual bases,2.如果一定要用,尽可能避免在其中放置数据。

 

此外,在设计时可以将public继承与private继承加以结合:
class CPerson: public IPerson, private PersonInfo {}
使用“public继承接口”和“private继承实现”。

 

 

保姆级教程:用Jetson Orin Nano和ROS2 Humble搞定PIXhawk 4飞控通信(含配置文件详解) 本文提供了一份详细的Jetson Orin Nano与PIXhawk 4飞控通信配置指南,涵盖硬件连接、ROS2 Humble环境搭建、MAVROS2配置及通信调试全流程。通过实战案例和配置文件详解,帮助开发者快速实现无人机上位机与飞控的稳定通信,适用于无人机开发与自动化控制场景。 阅读详情

相关推荐

蛋白质组学进阶指南 | (八)差异蛋白筛选与功能解析实战

本文是蛋白质组学差异蛋白筛选与功能解析的实战指南。详细讲解了如何利用R语言的limma包进行差异表达分析,结合FDR校正和差异倍数设定筛选关键蛋白,并通过火山图可视化结果。进一步介绍了使用clusterProfiler进行GO与KEGG功能富集分析,以及利用STRING数据库和Cytoscape构建蛋白互作网络以识别枢纽分子,最终串联分析形成可验证的生物学假说。

weixin_29208077的博客 745

Effective C++: Item 32 (转)

Effective C++: Item 32 (转)[@more@]Item 32: Postpone variable definitions as long as possible.So you subscribe to t...

ciya3282的博客 150

国产Flash替代方案:手把手教你用XSCT烧写ZYNQ7045的BOOT.BIN(附完整命令解析)

本文详细介绍了国产Flash替代方案在ZYNQ7045上的应用,通过XSCT工具链实现BOOT.BIN的精准烧写。内容涵盖国产Flash兼容性检查、PetaLinux环境搭建、XSCT烧写全流程及故障排查,帮助开发者高效完成国产化替代,提升硬件开发效率。

weixin_33670786的博客 429

Effective C++读书笔记(21)

昨天颓废了 今天*2 条款32:确定你的public继承塑模出is-a关系 Make sure public inheritance models “is-a” 使用C++语言进行面向对象编程时最重要的规则就是:publicinheritance意味着"is-a"关系。 如果令class D ("Derived") 从 class B ("Base") public继承,就是在告诉

pandawuwyj的专栏 912

Nexys4DDR+OV7670实现图像灰度显示系统嵌入式

通过对硬件平台的准备、Vivado工程配置、OV7670驱动程序的编写、图像灰度处理算法的设计以及系统集成与测试,我们成功实现了一个基于嵌入式系统的图像处理应用。当系统运行时,OV7670摄像头模块将采集到的图像传输到FPGA芯片中,然后通过图像灰度处理算法将彩色图像转换为黑白图像,并在显示设备上进行显示。OV7670摄像头模块的驱动程序是实现图像采集的核心。以上代码中,我们使用了Xilinx提供的XGpio和Xil_In32函数来进行OV7670摄像头数据的读取和GPIO的初始化。OV7670驱动程序。

WangWEel的博客 338

OpenHarmony开发一个App,安装到BearPi-HM Micro开发板

建议先阅读我们这篇,这里面详细介绍了,以及hap包安装的全过程。本篇是介绍如何开发一个App,然后安装到开发板上,比如hap包,无法安装等问题。

Halifax 1030

C++箴言:确保公开继承模拟“is-a”

zzy5177的专栏 286

82、yolov11检测模型迁移瑞芯微rk3588和使用昇腾设备300i DUO卡推理 batch=1/3,支持昇腾NMS迁移npu推理

本文介绍了使用昇腾设备进行分割推理的测试流程,包括两种测试方式(cann+onnx和om)。首先验证300iDUO卡的可用性,随后创建Docker镜像和容器以搭建独立环境。通过从指定仓库拉取Ubuntu 20.04镜像,创建容器并映射目录。进入容器后安装必要组件(Python3、GCC等)和系统工具(pciutils、net-tools等),为后续模型转换和迁移做准备。整个流程旨在构建可交付给第三方的标准化测试环境。

sxj731533730 1210

Effective C++ 3nd 读书摘要(Third Edition 55 Specific Ways to Improve Your Programs and Design)

一、让自己习惯C++ Item1. 视C++为一个语言联邦 C++由以下部分组成:C、Object-Oriented C++、Template C++、STL Item2. 尽量以const、enum、inline代替#define Item3. 尽可能使用const 1.一共有这样几种const用法:char greeting[] = "Hello";

thy专栏 1302

华为OD技术面八股_C++_05

汇总华为OD技术面C++方向技术面八股文,提供详细解答。

qq_45776114的博客 413

补丁1.0:使用Eviews做ADF检验

补丁1.0:使用Eviews做ADF检验

Jet4505的博客 1961

Effective C++ 3nd 读书摘要(七、模板与泛型编程)Item41 - 48

七、模板与泛型编程C++ template mechanism is itself Turing-complete: it can be used to compute any computable value. Item41. 了解隐式接口和编译期多态对class而言,接口是显式的,以函数签名为中心;多态是通过virtual函数发生于运行期。对template来讲,接口是隐式的,奠基于有

thy专栏 1050

【GameFramework框架】三、快速启动

这篇文章就带领大家如何快速启动GameFramework框架。

优快云博客专家,Unity3D高级软件工程师,《Unity 3D从入门到实战》作者。 4429

Effective C++ 3nd 读书摘要(一、让自己习惯C++ ; 二、构造,析构,赋值运算)Item1 - 12

一、让自己习惯C++Item1. 视C++为一个语言联邦C++由以下部分组成:C、Object-Oriented C++、Template C++、STL Item2. 尽量以const、enum、inline代替#define Item3. 尽可能使用const1.一共有这样几种const用法:char greeting[] = "Hello";char *p = greetin

thy专栏 916

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Effective C++ 3nd 读书摘要(三、资源管理 ;四、设计与声明;五、实现)Item13 - 31

三、资源管理Item13. 以对象管理资源在构造函数中获得资源并在析构函数中释放资源。如tr1::shared_ptr Item14. 在资源管理类中小心copying行为抑制copying、施行引用计数法 Item15. 在资源管理类中提供对原始资源的访问一如Item18的忠告,通常显式转换函数如get()、string::c_str()是比较受欢迎的,因为不太可能被误用。 

thy专栏 891

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Effective C++ 3nd 读书摘要(八、定制new和delete)Item49 - 52

八、定制new和deleteItem49. 了解new-handler的行为当然operator new抛出异常以反映内存需求出错之前,会先调用一个客户指定的错误处理函数(new-handler)。namespace std {  typedef void (*new_handler)();  new_handler set_new_handler(new_handler p) throw();}

thy专栏 890

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Effective C++ 3nd 读书摘要(九、杂项讨论)Item53 - 55

九、杂项讨论Item53. 不要轻忽编译器的警告比如:class B {public: virtual void f() const;};class D: public B {public: virtual void f();}; 编译器会警告:warning: D::f() hides virtual B::f()因为D中的f()没有const。 

thy专栏 794

深挖C++:类和对象(中)

(先进后出)

xys_678的博客 254

ThunderKittens 深度解析:一个不基于 MLIR 的 C++ 模板 GPU DSL

Triton 是"让更多人能写 GPU kernel",ThunderKittens 是"让会写的人写得更爽"。前者用 MLIR 换易用性,后者用 C++ 模板换可控性。它们不是替代关系,而是覆盖了 GPU 编程光谱的两端。ThunderKittens 的出现,本质上是对"GPU DSL 必须基于 MLIR"这一默认假设的挑战。编译期类型系统本身就可以是一个强大的 DSL 基础设施,不需要中间 IR,不需要黑盒 pass,也能实现 tile 级抽象和零运行时开销。

Maxwell_Newton的博客 349

C++移动构造函数详解

移动构造函数是C++11引入的一种特殊构造函数,用于从临时对象(右值)"窃取"资源来初始化新对象,而不是进行昂贵的深拷贝。char* data;public:// 移动构造函数:参数是右值引用 &&// 关键:把源对象的资源置空。

拒绝AI文,努力在AI时代写出感动人心的好文章 394

跟我学c++中级篇—类型定义的方式

本文系统阐述了编程中类型定义的重要性及c++中的实现方式。重点对比了宏定义、typedef与modern using三种机制,指出using在可读性、灵活性和模板支持上的优势,推荐优先使用。同时提醒开发者注意别名滥用、类型歧义、错误信息冗长等问题,强调统一规范与合理设计。最终结论:在现代c++开发中,应以using为主,兼顾简洁性与可维护性,避免陷入命名混乱与编译困境。

fpcc的专栏 88

【C++——类和对象(上)】筑基篇:以封装奠定面向对象之基

本文系统梳理C++类与对象的核心知识点,涵盖类的定义、访问限定符(public/private)、类作用域、对象实例化及内存布局。重点解析封装思想、this指针机制、空类大小为1字节的原因,以及类与对象在内存中的存储差异。通过对比C语言结构体与C++类,揭示面向对象设计的优势:数据保护、接口统一、命名隔离与代码可维护性提升。内容由浅入深,适合作为学习笔记与复习参考。

2602_95684935的博客 492

C++ 函数模版

模板参数:● template ,T 就是类型占位符,名字可以自定义,习惯用T● 占位符可以在函数返回值、形参、函数内部当作类型使用使用要点模板代码一般写在头文件:编译器需要看到完整模板源码,才能在每个编译单元完成实例化全局函数、类内成员函数都可以写成模板实例化发生在编译阶段,不是运行时隐式实例化:调用时编译器自动推导实参类型,生成对应版本函数。

2501_94041724的博客 307

C++ 运行时多态与虚函数机制全面剖析【面试重点】

构成C++ 运行时多态必须是基类的指针或者引用调用虚函数。被调用的函数必须是虚函数,并且派生类必须对该虚函数完成重写/覆盖(Override)。只有基类的指针或引用才能既指向基类对象,又指向派生类对象(切片机制);而只有完成了虚函数重写,派生类与基类才具备不同的函数行为,达到“指向谁就调用谁”的效果。在类成员函数的前面加上virtual关键字修饰,该成员函数就成为了虚函数。public:// 成员函数前加 virtual 修饰,声明为虚函数。

Fuyo_0209的博客 450

#SQLite 数据库笔记一:(概念 / 终端指令 / SQL 语句 / C 编程 / 回调函数)

数据库 = 数据的仓库,假设数据是海量。能力说明存储数据持久化保存,程序退出数据还在统计数据、分组、排序数据管理增、删、改、查(CRUD)嵌入式设备上也会用数据库(单片机网关、路由器、工业 HMI 都常见),因为 sqlite 体积小、无需服务进程、单文件即可。数据库 = 库 > 表 > 记录(行) > 字段(列)sqlite3 = 开源、C 写的、单文件、免安装、最多 2T 的嵌入式关系型数据库。

lwq20051110的博客 251

1-10 PostgreSQL中多表连接全解:inner/left/right/full/cross join

本文基于 PostgreSQL 15+ 完整拆解 5 种主流连接:内连接、左连接、右连接、全连接、笛卡尔连接。结合可落地的测试数据,演示每种连接的执行逻辑、返回结果,重点剖析 NULL 值对 JOIN 匹配的核心影响,彻底解决多表连接数据丢失、匹配异常、结果错乱的问题。

zhangjw34的专栏 105
上一篇: Effective C++ 3nd 读书摘要(三、资源管理 ;四、设计与声明;五、实现)Item13 - 31
下一篇: Effective C++ 3nd 读书摘要(七、模板与泛型编程)Item41 - 48
thy38
博客等级 码龄19年 184粉丝 116原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值