Polymorphism problem w/local functions?

Magnus Lie Hetland magnus at hetland.org
Mon Jul 18 05:11:29 PDT 2011


Is it intended that local functions can't be polymorphic?

Example:

void foo(int x) {}
void foo(string x) {}

void bar() {
    void foo(int x) {}
    void foo(string x) {}
}

void main() {
}

The error (at line 6) is "declaration foo is already defined".

The code compiles if you comment out at least one of the local 
functions (but not if you, for example, comment out the global ones, of 
course).

Is this a bug, or am I just missing the reasoning behind it? Any 
workarounds? (I'm still at 2.052, so maybe this works in the new 
version?)

-- 
Magnus Lie Hetland
http://hetland.org



More information about the Digitalmars-d-learn mailing list