Error: template instance does not match template declaration

Vitalii yvitaliy1980 at yandex.ru
Wed Nov 17 12:55:15 UTC 2021


Thank you for response, Tejas!

What I intended to do was make a class with only two states 
("Inspect" - do some analysis, "Execute" - do some stuff). That's 
why I tried to use template specialization.

The following code compiles successfully, but return *"fun with 
unknown"* instead of *"fun with Mode1"*, as I supposed. I think I 
missed some "static" thing in my code, but can't find any working 
examples. Any ideas?

```
import std.stdio : writeln;

enum Mode1;
enum Mode2;

class Worker(Mode) {
	this() {}

	void fun() {
		static if (is(typeof(Mode) == Mode1)) {
			writeln("fun with Mode1");
		}
		else static if (is(typeof(Mode) == Mode2)) {
			writeln("fun with Mode2");
		}
		else {
			writeln("fun with unknown");
		}
	}
}

void main() {
	auto W = new Worker!(Mode1)();
	W.fun();
}
```


More information about the Digitalmars-d-learn mailing list