www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - interface/template/class public/private issue

reply Regan Heath <regan netwin.co.nz> writes:
Can someone point out my error here?

--[test2.d]--
module test2;

interface A {
public:
	void fn();
private:
	void doStuff();
}

template B() {
public:
	void fn() {
		doStuff();
	}
private:
	ulong length = 0;
}

class C : A {
	mixin B;
public:
private:
	void doStuff() {
		length = 10;
	}
}

void main() {
}


D:\D\src\build>dmd test2.d
test2.d(19): class C B!().length is private


What does the mixin do to the public/private state/scope?

Regan.

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jun 22 2004
parent reply Sean Kelly <sean f4.ca> writes:
In article <opr90s39am5a2sq9 digitalmars.com>, Regan Heath says...
What does the mixin do to the public/private state/scope?
mixin works the same way as import, so 'private' delineates stuff that's not accessible outside the mixin itself. Sean
Jun 22 2004
parent reply Regan Heath <regan netwin.co.nz> writes:
On Wed, 23 Jun 2004 00:02:17 +0000 (UTC), Sean Kelly <sean f4.ca> wrote:
 In article <opr90s39am5a2sq9 digitalmars.com>, Regan Heath says...
 What does the mixin do to the public/private state/scope?
mixin works the same way as import, so 'private' delineates stuff that's not accessible outside the mixin itself.
Ahh. ok, but doesn't that mean I have to split my mixin into 2 mixins in order to mix some of it as private and some as public i.e. template FooPrivate { int a; } template FooPublic { int b; } class Bar { private: mixin FooPrivate; public: mixin FooPublic; } instead of simply being able to go: template Foo { private: int a; public: int b; } class Bar { mixin Foo; } Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jun 22 2004
parent Regan Heath <regan netwin.co.nz> writes:
In fact.. I cannot seem to work out how to mixin something giving it 
'private' access.
eg.

template md() {
	uint[4] context = [
		0,1,2,3
	];
}

struct md5 {
	mixin md;
	void foo() {
		context[0] = 1;
	}
}

void main() {
	md5 m;
	m.context[1] = 3;
}

I want the foo fn in md5 to be able to access context, but main not to be 
able to.
I tried every permutation of adding public private to various places, no 
luck.

Help!

Regan.

On Wed, 23 Jun 2004 13:25:41 +1200, Regan Heath <regan netwin.co.nz> wrote:
 On Wed, 23 Jun 2004 00:02:17 +0000 (UTC), Sean Kelly <sean f4.ca> wrote:
 In article <opr90s39am5a2sq9 digitalmars.com>, Regan Heath says...
 What does the mixin do to the public/private state/scope?
mixin works the same way as import, so 'private' delineates stuff that's not accessible outside the mixin itself.
Ahh. ok, but doesn't that mean I have to split my mixin into 2 mixins in order to mix some of it as private and some as public i.e. template FooPrivate { int a; } template FooPublic { int b; } class Bar { private: mixin FooPrivate; public: mixin FooPublic; } instead of simply being able to go: template Foo { private: int a; public: int b; } class Bar { mixin Foo; } Regan
-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jun 23 2004