模板类的继承

C++模板类的继承1 :模板类继承模板类 大学时代旧作。       模板类的继承是C++中较为高级的一种用法,其语法与普通C++类的继承略有差别。本文实例演示了一个通过C++模板类继承实现排序算法的案例。代码如下: 1.   实现List基类 #ifndef LIST_H #define LIST_H #include using std::cout; using std::endl; enum Error_co 阅读详情

模板类的继承

模板类的继承包括四种:

1.(普通类继承模板类)

template<class T>
class TBase{
    T data;
……
};
class Derived:public TBase<int>{
……
};


2.(模板类继承了普通类(非常常见))

class TBase{
……
};
template<class T>
class TDerived:public TBase{
T data;
……
};


3.(类模板继承类模板)

template<class T>
class TBase{
T data1;
……
};
template<class T1,class T2>
class TDerived:public TBase<T1>{
T2 data2;
……
};


4.(模板类继承类模板,即继承模板参数给出的基类)

#include<iostream>
using namespace std;

class BaseA{
public:
    BaseA(){cout<<"BaseA founed"<<endl;}
};
class BaseB{
public:
    BaseB(){cout<<"BaseB founed"<<endl;}
};
template<typename T, int rows>
class BaseC{
private:
    T data;
public:
    BaseC():data(rows){
        cout<<"BaseC founed "<< data << endl;}
};
template<class T>
class Derived:public T{
public:
    Derived():T(){cout<<"Derived founed"<<endl;}
};

void main()
{
    Derived<BaseA> x;// BaseA作为基类
    Derived<BaseB> y;// BaseB作为基类
    Derived<BaseC<int, 3> > z; // BaseC<int,3>作为基类
}


STL模板类的继承 1.STL模板类的继承符合普通的继承规则   *STL提供的模板类有时并不符合需求,例如,vector类并没有提供下标越界检测。这时便可以通过简单的继承,达到目的。   Example: #include #include #include  using namespace std; template class myVector:public vec 阅读详情

相关推荐

模板类的继承问题

首先大家来看这段代码: class A { public: void Show() { cout << "A::Show() !!!" << endl; } void Fun() { cout << "A::Fun() !!! " << endl; } }; class B { public: voi

ooooo12345re的博客 2859

跟我学c++中级篇——模板的继承

模板不管用得多少 ,总会遇到一些很古怪的错误,但这些错误其实是编译器不友好,或者说模板比较复杂导致编译无法特别准确的提供一些信息造成的。所以重点还是要把模板的基础知识学清楚,一点点的推导出来,再配合相关的错误信息,就可以较快的解决问题。网上还有先写非模板代码然后 再用模板代码改写的。这样也是一个不错的方法,虽然有点费事儿,但只要用在复杂的情况下就好了。重点在于不断的反复的把模板的知识对照着代码编写,熟悉后自然就渐渐明白道理,再写就逐渐顺手多了。

fpcc的专栏 3355

stackelberg博弈_博弈论、多智能体、强化学习(随便记点东西)

多智能体应用场景:已实现:游戏AI。正在努力:UAV,物资运输,快递分发,交通系统。未来:社会学,预测群体行为,城市区域合作,国际关系。博弈论基本定义:玩家集合: 策略集合: 收益函数: 囚徒困境:两智能体矩阵博弈坦白抵赖坦白1,13,0抵赖0,32,2占优策略与最佳应对:上表中两者均具有占优策略,即无论如何都应该选坦白。那么构造下表。坦白抵赖坦白1,13,0抵赖0,12,2对于玩家一来说,坦白...

weixin_39611722的博客 2997

C++模板类与继承

C++模板类与继承

Crush_66的博客 4312

别再死记硬背HJB方程了!用Python数值求解一个简单最优控制问题(附完整代码)

本文通过Python数值求解Hamilton-Jacobi-Bellman(HJB)方程,帮助读者从工程实践角度理解最优控制问题。教程涵盖从建立简单车辆控制模型到离散化HJB方程、实现值迭代算法及可视化结果的完整流程,适合具备Python基础的开发者学习。

weixin_42520796的博客 371

测试dali协议的软件,DALI2.0和DALI1.0完美兼容同一个模块,测试每项可过协议

DALI2.0和DALI1.0完美兼容同一个模块,测试每项可过协议深圳聚积智能 夏先生 13246760327 QQ 349098308■IEC62386-102(V2.0)通过测试内容IEC62386-102/2.1/Test preambleIEC62386-102/3.1/Polarity testIEC62386-102/3.2/Maximum and minimum system v...

weixin_35343788的博客 1351

类模板的继承

当类模板碰到继承时,需要注意以下几点: 1)当子类继承到父类是一个类模板时,子类在声明时,需要指出父类中T的数据类型。 2)如果不指定,编译器无法给子类分配内存空间。 3)如果想灵活指定出父类中T的类型,子类也需要变成类模板。 #include <iostream> using namespace std; #include <typeinfo> //类模板与继承 /* template<class T> class Base{ public: T m; };

m0_64837135的博客 2950

51单片机AHT20-21源代码

传感器输出经过 标定的数字信号,标准 I 2 C 格式。AHT20 配有一个全新设计的 ASIC专用芯片、一 个经过改进的MEMS半导体电容式湿度传感元件和一个标准的片上温度传感元件,其 性能已经大大提升甚至超出了前一代传感器的可靠性水平,新一代温湿度传感器, 经过改进使其在恶劣环境下的性能更稳定。但是现在网上的大多数原码都是针对stm32等的这种多位单片机,而我们都知道51单片机是8位单片机,无法对浮点数进行运算,对32位的整数计算有时候也不是很准确,所以我对网上stm32的例程进行了修改。...

wd0710的博客 4549

【C++】模板进阶|继承

模板进阶、继承的详细讲解

大三小白C++进阶之路 2921

6、硬件工程师笔试面试知识器件篇——电容(2025版本)

本文系统介绍了电容器的基本原理、类型分类、应用场景及相关设计问题。首先阐述了电容的定义、工作原理及计算公式,详细分析了陶瓷、电解、薄膜、钽等不同类型电容的特性差异。针对高频电路设计,重点讨论了如何评估和优化电容器的寄生效应(ESR/ESL)、频率特性、温度特性等关键参数。文章还提供了PCB布局优化策略,包括缩短走线、多层板设计、去耦网络配置等方法。最后涵盖了电容器寿命计算、稳定性评估及电源电路设计中的纹波电流处理等实用内容,为硬件工程师提供了全面的电容器选型和应用指南。

XU157303764的博客 3872

【推荐100个unity插件之24】实现2d交互式草树叶和随风飘动的效果——pixelgraphics插件

【推荐100个unity插件之23】实现2d交互式草树叶和随风飘动的效果——pixelgraphics插件

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 1683

【c++】模板类继承模板类

C++继承访问权限:https://www.runoob.com/cplusplus/cpp-inheritance.html 1. 普通类继承 demo #include <iostream> using namespace std; // 基类 class Shape { public: void setWidth(int w) { width = w; } void setHeight(int h) { hei

ystraw - Come on!!! 5417

Realtek千兆PHY RTL8211FS相关寄存器操作详解

通过合理配置和控制RTL8211FS寄存器,您可以实现对以太网的各种功能和参数的控制和配置。请注意,具体的寄存器操作和配置值可能因具体需求而有所不同,您应参考RTL8211FS芯片的数据手册以获取准确的寄存器说明和操作规范。我们将提供相应的源代码示例,以帮助您理解和实施这些操作。通过操作这些寄存器,我们可以配置和控制RTL8211FS芯片的各种功能和参数。需要注意的是,具体的寄存器操作和配置值会根据您的具体需求而有所不同。您需要参考RTL8211FS芯片的数据手册以获取详细的寄存器说明和操作规范。

RlDart的博客 2660

C++模板类的继承2:普通类继承模板类

在上一篇文章中,介绍了C++中模板类继承的实现。本文补充介绍如何从C++模板类中派生出一个普通类,或者说实现一个普通类A,继承至一个模板类B。 1.实现List基类(模板类) #ifndef LIST_H #define LIST_H #include using std::cout; using std::endl; enum Error_code { underflow, overfl

深度学习,计算机视觉 8652

YOLOv13改进策略【小目标改进】| Shape-NWD:融合改进,结合Shape-IoU和NWD 更好地适应小目标特性

Bw−wgt2h−hgt2weight2Bweight2w−wgt​2h−hgt​2​其中weight2weight = 2weight2。

Limiiiing的博客 587

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

C++ —— 模板类与继承

C++ —— 模板类与继承

MaoSiri的博客 804

深度学习工具包 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'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('DeepLearnToolbox'));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('state',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'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',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 = 'sigm';%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, 'Too big error');```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('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';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)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';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, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% 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'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 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, 'Too big error');```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('state',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, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',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, 'Too big error');%% ex3 neural net with dropoutrand('state',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, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % 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, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % 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, 'Too big error');%% 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('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % 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, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

模板类的继承总结(五十三)

原址 模板类的继承包括四种: 1.(普通类继承模板类) 2.(模板类继承了普通类(非常常见)) 3.(类模板继承类模板) 4.(模板类继承类模板,即继承模板参数给出的基类) 其中,普通类继承模板类比较简单,如 1 templateclass T> 2 class TBase{ 3 T data; 4 …… 5 }; 6 class Deri

Android系统攻城狮 1万+

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

模板类与继承

模板类的继承

记录我目之所及的世界 416

[C++]模板类的继承

1. 模块基类不用指定传参类型 // 定义模板类,作为父类 template <typename T> class People { public: T x; People(){}; People(T a):x(a){}; }; // 定义派生类 template <typename T> class Man:public People<T> { public: T y; Man(){}; Man(T a):y(a){}; Man(T a, T b).

xiaoyu_wu的博客 2396
上一篇: 总结软件设计原则
下一篇: 只用位运算交换两个数
普通网友
博客等级 码龄14年 9粉丝 21原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值