Structs with pointers?

Sean Eskapp eatingstaples at
Sat Jan 22 14:53:03 PST 2011

== Quote from Sean Eskapp (eatingstaples at's article
> Why doesn't this code work?
> struct Bar
> {
> 	int* x;
> }
> void foo(Bar a) {}
> void main()
> {
> 	const a = Bar();
> 	foo(a);
> }
> But replacing int* with some other type works fine? Even if a write a postblit
> function for Bar, it still fails to compile.

Nevermind, I realized it's because constness is transitive in pointers. A const
struct with a pointer member has a const pointer member, and those can't be
implicitly cast to non-const pointer members.

More information about the Digitalmars-d-learn mailing list