Having trouble with parameters in partial specialization

Hey everyone,

I can't figure out what I'm doing wrong! I am working on redeveloping a smart pointer class, and I'm not terribly familiar with partial specialization of templated classes. Everything looks okay, and I've checked up on the net for advice, but I think I need more 'specialized' help on this one! Here's what I've got:

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
28
29
enum OwnershipType	{REFERENCE_COUNTED, REFERENCE_LINKED, DESTRUCTIVE_COPY, DEEP_COPY, COPY_ON_WRITE};
enum ConversionType	{CONVERSION_NOTALLOWED = 0, CONVERSION_ALLOWED};
enum ErrorType		{ASSERT_INITIALIZE, ASSERT_DEREFERENCE, REJECT_NULL_INITIALIZE, REJECT_NULL_DEREFERENCE, NO_CHECK};
enum StorageType	{RAW_POINTER, ARRAY_POINTER, LOCKED_POINTER};

template 
	<
		typename T, 
		OwnershipType otype = REFERENCE_COUNTED, 
		ConversionType ctype = CONVERSION_NOTALLOWED, 
		ErrorType etype = ASSERT_INITIALIZE,
		StorageType stype = RAW_POINTER
	> 
class CPointer	{};

template <typename T, OwnershipType otype, ConversionType ctype, ErrorType etype, StorageType stype> class CPointer <T, REFERENCE_COUNTED, ctype, etype, stype>
{defintion...};

template <typename T, OwnershipType otype, ConversionType ctype, ErrorType etype, StorageType stype> class CPointer <T, REFERENCE_LINKED, ctype, etype, stype>
{definition...};

template <typename T, OwnershipType otype, ConversionType ctype, ErrorType etype, StorageType stype> class CPointer <T, DESTRUCTIVE_COPY, ctype, etype, stype>
{definition...};

template <typename T, OwnershipType otype, ConversionType ctype, ErrorType etype, StorageType stype> class CPointer <T, DEEP_COPY, ctype, etype, stype>
{definition...};

template <typename T, OwnershipType otype, ConversionType ctype, ErrorType etype, StorageType stype> class CPointer <T, COPY_ON_WRITE, ctype, etype, stype>
{definition...};


When I compile, I get this message (for each one of my declarations):
error C2764: 'otype' : template parameter not used or deducible in partial specialization 'CPointer<T,REFERENCE_COUNTED,ctype,etype,stype>'

Now, I am using a different 'otype' for each definition, but I don't need to use this 'otype' inside the definition since each definition is custom-made for each 'otype'. Also, inside of each definition, when I overload operators such as =, or need to define class members, do I need to define it as:

1
2
CPointer& operator = (const CPointer& rhs) {definition...}
CPointer value;

or
1
2
CPointer<T, REFERENCE_COUNTED>& operator = (const CPointer<T, REFERENCE_COUNTED>& rhs) {definition...}
CPointer<T, REFERENCE_COUNTED> value;
?

I would like to think that I could use the latter since that would help prevent ambiguity when writing my main code. Any help is appreciated!
Update:

I have done some studying up on 'explicit specialization' of class templates. After fiddling for a while, (and looking to change the things that I already had correct), I finally found the answer. Since each declaration had it's OwnershipType parameter defined, the OwnershipType had to be left out of the template list:
1
2
template <typename T, ConversionType ctype, ErrorType etype, StorageType stype> class CPointer <T, REFERENCE_LINKED, ctype, etype, stype>
{definition...};

After thinking that the compiler error was trying to tell me that it couldn't determine which definition to use when creating an object, I finally can make sense of it now. Maybe this will help someone else out there!

bool ImADummy() const {return true;}
Topic archived. No new replies allowed.