I was calling it from another module: in file Test.d: class Test { private: int x; void testNonTemplate() { } template test() { void test() {x= 100;} } public: int getX() {return x;} } In file main.d: import Test; Test t = new Test; t.test(); /*ok*/ t.testNonTemplate(); /*error*/ writeln(t.getX()); /* prints 100 */ I am using dmd 2.052