struct Person {
STD: : string m_name;
Short m_age;
};
//template class, used to store two Numbers and exchange, under normal circumstances are implicit instantiation
Template
The class Test {
Private:
T m_a;
T m_b;
Public:
The Test (T, a, T, b);
Void swap ();
Void the show () the const;
};
Template
Test: : Test (T, a, T, b) : m_a (a), m_b (b) {
}
Template
Void Test: : swap () {
T temp=m_a;
M_a m_b=;
M_b=temp;
}
Template
Void Test: : show () const {
STD: : cout & lt; <"A:" & lt;STD: : cout & lt; <"B:" & lt; }
//show the instantiation class template
The template
The class Test;
//display specific class template to handle structure
Template<>
The class Test{
Private:
The Person m_a;
The Person m_b;
Public:
The Test (Person& A, Person& B);
Void swap ();
Void the show () the const;
};
Template<>
Test: : Test (Person& A, Person& B) : m_a (a), m_b (b) {
}
Template<>
Void Test: : swap () {
Auto temp=m_a. M_age;
M_a. M_age=m_b. M_age;
M_b. M_age=temp;
}
Template<>
Void Test: : show () const {
STD: : cout & lt; <"A:" & lt;STD: : cout & lt; <"B:" & lt; }
CodePudding user response:
I recently also encountered such a problem, but I think the STL source is directly in the class content within the definition of function, and is not an error, and then I did.CodePudding user response: