Search code examples
d

Error: template std.array.Appender!(string).Appender.put does not match any function


I get an error

Error: template std.array.Appender!(string).Appender.put does not match any 
function template declaration 

I am trying to use the Appender. Can you tell me how to make it work?

import std.array;
import std.stdio;

    void app(inout Appender!(string) as)
    {
       char ch = 'o';
       as.put(ch);
    }

    void main()
    {
       auto app2 = appender!string();
       //writeln(typeid(app));
       app2.put('g');
       app(app2);
    }

Solution

  • Change inout to ref.

    inout is used to transfer cont/immutable/none attribute from function arguments to its parameters. ref is for transferring function arguments by references.