template specialization

Hi, How do I specialize a class template that depends on multiple type definitions template<typename T, class V, class M> class something? I would like the class to behave differently if M==typeA.
Last edited on
Try
1
2
3
4
5
template <typename T, class V> 
class something<T,V,typeA>
{
    // your implementation here...
}

Did that help?
Last edited on
What if I want to specialize only one method of the class?
The program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

using namespace std;

template <class T>
class X
{
public:
	void func()
	{
		cout << "default version called.\n";
	}
};

template <> void X<int>::func()
{
	cout << "int version called.\n";
}

int main()
{
	X<char> xc;
	X<int> xi;

	xc.func();
	xi.func();
}

will output

default version called.
int version called.
Topic archived. No new replies allowed.