digitalmars.D.learn - Templates with the same name as methods not legal?
- Simen Haugen (22/22) Apr 19 2007 If I try to call a template when a method with the same name exists I ge...
- Frits van Bommel (5/27) Apr 19 2007 Naming the member function "isInteger" hides the "isInteger" name for
- Simen Haugen (3/30) Apr 19 2007 I though the compiler could see the differance. Thanks.
If I try to call a template when a method with the same name exists I get a compiler error: template isInteger(T) { static if (is(T == int)) const bool isInteger = true; else const bool isInteger = false; } class Test { bool isInteger() { return isInteger!(int); // Yields an compiler error } } Gives me the error: test.d(15): template instance isInteger is not a template declaration, it is a function To me it seems this should be legal as my method doesn't take any template parameters and the compiler should understand that the template should be called.. There must be something I don't understand here...
Apr 19 2007
Simen Haugen wrote:If I try to call a template when a method with the same name exists I get a compiler error: template isInteger(T) { static if (is(T == int)) const bool isInteger = true; else const bool isInteger = false; } class Test { bool isInteger() { return isInteger!(int); // Yields an compiler error } } Gives me the error: test.d(15): template instance isInteger is not a template declaration, it is a functionNaming the member function "isInteger" hides the "isInteger" name for the template while inside the class. The method should "return .isInteger!(int);" instead (notice the added '.') to use the global isInteger template.
Apr 19 2007
I though the compiler could see the differance. Thanks. "Frits van Bommel" <fvbommel REMwOVExCAPSs.nl> wrote in message news:f07lk7$29kv$1 digitalmars.com...Simen Haugen wrote:If I try to call a template when a method with the same name exists I get a compiler error: template isInteger(T) { static if (is(T == int)) const bool isInteger = true; else const bool isInteger = false; } class Test { bool isInteger() { return isInteger!(int); // Yields an compiler error } } Gives me the error: test.d(15): template instance isInteger is not a template declaration, it is a functionNaming the member function "isInteger" hides the "isInteger" name for the template while inside the class. The method should "return .isInteger!(int);" instead (notice the added '.') to use the global isInteger template.
Apr 19 2007