传智扫地僧课程学习笔记。
结合类模板的实现机制,
你应该能想到下面问题的结论,
那就是具体到不同的类,其分别有一份static变量,
#include "iostream"
using namespace std;
template <typename T>
class AA
{
public:
static T m_a;
};
template <typename T>
T AA<T>::m_a = 0;
void main()
{
AA<int> a1, a2, a3;
a1.m_a = 10;
a2.m_a++;
a3.m_a++;
AA<char> b1, b2, b3;
b1.m_a = 'a';
b2.m_a++;
b3.m_a++;
system("pause");
}
两个m_a分别是,12,‘c’