首页 > 编程语言 >C++ 模板类继承

C++ 模板类继承

时间:2022-09-21 17:00:16浏览次数:69  
标签:继承 void C++ class template Test public 模板

template<class T>
class A
{
protected:
    void Test() {
        printf("%f",0.1f);
    }
};
template<class T>
class B:public A<T>
{
public:
    void Test2() {
        Test();
    }
};

去除模板可以正常的使用,但是当加上模板后,父类的Test函数将不能正常被调用。

错误 C3861 “Test”: 找不到标识符

template<class T>
class A
{
protected:
    void Test() {
        printf("%f",0.1f);
    }
};
template<class T>
class B:public A<T>
{
public:
    void Test2() {
        this->Test();
    }
};

 使用父类的方法需要加上zhis关键字,用对象的地址去call方法。

 

 从内存上看没有方法表,从调用过程看直接使用编译过的地址去call父类的方法。

标签:继承,void,C++,class,template,Test,public,模板
From: https://www.cnblogs.com/zjr0/p/16716239.html

相关文章

  • redis基础系列~监控模板
    {"annotations":{"list":[{"builtIn":1,"datasource":"--Grafana--","enable":true,"hide":true,......
  • UEC++ 资源加载(四)模板资源拾取类
    TSoftObjectPtr和TSoftClassPtr模板类帮助我们在进行资源操作时增加了类型安全检查,我们可以在细节面板中根据给定的模版类型拾取对应的资源,以获得更加高效的操作!同样的,TS......
  • C++ time_t与格式化日期时间字符串的转换
    开发中对于特定格式的日期和格式获取很常见,这里给出一系列工具函数:#include<time.h>#include<sstream>usingnamespacestd;//time转格式化字符串=============......
  • 2022年vue3 10大开源后台管理系统模板
    当你写项目的时候,如何快速的完成一个项目的搭建,这个时候就需要借助到一些模板了,前端开发的一个好处就是,各类UI模板都是相当的齐全的,直接拿来用就可以了,脱离了一行又一行垒......
  • UEC++ 资源加载(一)直接属性引用
    1、编辑器直接加载:通过使用属性宏标记UPROPERTY(Edit三个都可以3)来将资产对象指针暴露到编辑器面板,从而直接从编辑器面板拾取资产。注意:UClass类指针,专门用来拾取类模版......
  • c++ 字符串常用操作
    查找搜索一般使用find,rfind即可,如果找不到,返回std::npos.size_tfind(conststring&str,size_tpos=0)const;size_tfind(constchar*s,size_tpos=0)......
  • qmlRegisterType 注册C++类型出现 module not fount
    使用 qmlRegisterSingletonType或 qmlRegisterType想QML注册C++类,按照使用文档上方法添加如下:qmlRegisterSingletonType<CProtoInfoModel>("LdpModel",1,0,"p......
  • 使用easypoi导出word模板
    官方文档: http://easypoi.mydoc.io/pom.xml<dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-spring-boot-starter</artifactId><versio......
  • JAVA线段树模板
    publicclassLineTree{int[]tree,nums;intn;publicLineTree(int[]nums){this.nums=nums;n=nums.length;tree=newi......
  • 排序方法(C++ 、递归方法)
    1#include<iostream>2#include<vector>3usingnamespacestd;45vector<int>sort(intn,vector<int>inputs,intp){6intmin=inputs[p],pos......