您的位置:首页 > 科技 > IT业 > C++ 成员模板类

C++ 成员模板类

2024/10/5 14:01:15 来源:https://blog.csdn.net/qq_40135848/article/details/140084197  浏览:    关键词:C++ 成员模板类
#include <iostream>         // 包含头文件。
using namespace std;        // 指定缺省的命名空间。template<class T1, class T2>
class AA              // 类模板AA。
{
public:T1 m_x;T2 m_y;AA(const T1 x, const T2 y) : m_x(x), m_y(y) {}void show() { cout << "m_x=" << m_x << ",m_y=" << m_y << endl; }template<class T>class BB{public:T m_a;T1 m_b;BB() {}void show();};BB<string> m_bb;template<typename T>void show(T tt);
};template<class T1, class T2>
template<class T>
void AA<T1,T2>::BB<T>::show() { cout << "m_a=" << m_a << ",m_b=" << m_b << endl; 
}template<class T1, class T2>
template<typename T>
void AA<T1,T2>::show(T tt) {cout << "tt=" << tt << endl;cout << "m_x=" << m_x << ",m_y=" << m_y << endl;m_bb.show();
}int main()
{AA<int, string> a(88, "我是一只傻傻鸟。");a.show();a.m_bb.m_a = "我有一只小小鸟。";a.m_bb.show();a.show("你是一只什么鸟?");
}

推荐一个零声学院项目课,个人觉得老师讲得不错,分享给大家:
零声白金学习卡(含基础架构/高性能存储/golang云原生/音视频/Linux内核)
https://xxetb.xet.tech/s/3Zqhgt

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com