Say I have type and a function look like this:
class Foo
{
void* data;
Foo clone ()
{
auto c = new Foo;
c.data = data;
return c;
}
}
void bar (Foo foo)
{
auto c = foo.clone();
...
}
Since I'm not changing anything on foo I thought that it could
On 04/09/2012 04:49 PM, Jacob Carlborg wrote:
But now when I compile this code I get this error:
Error: cannot implicitly convert expression (this.data) of type
const(void*) to void*
Any idea how to solve this? Or would I need to drop const.
--
/Jacob Carlborg
Either clone the data too or
On 2012-04-09 17:30, Steven Schveighoffer wrote:
// untested
inout(Foo) clone() inout {
return new inout(Foo)(data);
}
Note, you can't post-assign data, since inout is effectively const
inside an inout function.
-Steve
Ok, that works. But then I want to modify the clone:
void bar (const
On Mon, 09 Apr 2012 13:51:17 -0400, Jacob Carlborg d...@me.com wrote:
On 2012-04-09 17:30, Steven Schveighoffer wrote:
// untested
inout(Foo) clone() inout {
return new inout(Foo)(data);
}
Note, you can't post-assign data, since inout is effectively const
inside an inout function.
-Steve
On Monday, April 09, 2012 19:51:17 Jacob Carlborg wrote:
On 2012-04-09 17:30, Steven Schveighoffer wrote:
// untested
inout(Foo) clone() inout {
return new inout(Foo)(data);
}
Note, you can't post-assign data, since inout is effectively const
inside an inout function.
-Steve
On 2012-04-09 19:56, Steven Schveighoffer wrote:
Then c.data cannot be the same reference as foo.data.
Counter-case:
void bar( const Foo foo)
{
auto c = foo.clone(); // assume this works;
*(cast(int*)c.data) = 6; // note even though I'm casting, there is no
removal of const, so this should be