-
-
Save Dounm/67bd2884a390630bd784706feaeee6b9 to your computer and use it in GitHub Desktop.
code snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// t.h | |
#include <iostream> | |
using namespace std; | |
template <typename T1, typename T2> | |
class A { | |
public: | |
void foo(); | |
}; | |
// t2.cpp | |
#include "t.h" | |
template<typename T1> | |
class A<T1, int> { | |
public: | |
void foo() { | |
cout << "T1, int" << endl; | |
} | |
}; | |
template<> | |
class A<int, int> { | |
public: | |
void foo() { | |
cout << "int, int" << endl; | |
} | |
}; | |
template class A<float, int>; | |
template class A<int, int>; | |
// t.cpp | |
#include "t.h" | |
int main() { | |
A<float, int> a; | |
a.foo(); // no error | |
A<int, int> a1; | |
a1.foo(); // undefined reference, why? | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment