www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - "Module is private" when calling function

reply Sean Eskapp <eatingstaples gmail.com> writes:
I have two modules:

foo.d:
public void Foo(int x) {}
private void Foo(string x) {}

private void Bar(string x) {}
public void Bar(int x) {}

main.d:
import foo;

void main()
{
	Foo(5); // OK
	Foo("Hello"); // error: function is private (correct)
	Bar(5); // error: module is private (incorrect)
	Bar("hello"); // error: function is private (correct)
}

With the errors demonstrated. When a public function is denoted below a
private function, the private function seems to intercept the overload. Is
this supposed to happen?
Jan 07 2011
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Friday 07 January 2011 03:54:29 Sean Eskapp wrote:
 I have two modules:
 
 foo.d:
 public void Foo(int x) {}
 private void Foo(string x) {}
 
 private void Bar(string x) {}
 public void Bar(int x) {}
 
 main.d:
 import foo;
 
 void main()
 {
 	Foo(5); // OK
 	Foo("Hello"); // error: function is private (correct)
 	Bar(5); // error: module is private (incorrect)
 	Bar("hello"); // error: function is private (correct)
 }
 
 With the errors demonstrated. When a public function is denoted below a
 private function, the private function seems to intercept the overload. Is
 this supposed to happen?

That looks like an error. The order than functions are declared in shouldn't matter. - Jonathan M Davis
Jan 07 2011