struct requiring this access for template?
mgen
bmeck at stedwards.edu
Sat Nov 15 16:47:17 PST 2008
I encountered an odd error while using template, it reduced to this... and I was wondering whats going on.
//Regex.d(20): Error: need 'this' to access member x
module templating;
import tango.io.Stdout;
public class TemplatedClass
{
const char[] pattern;
public this(char[] pattern){this.pattern=pattern;}
public char[] x()
{
return this.pattern;
}
}
public static TemplatedClass Templated()(char[] pattern)
{
return new TemplatedClass(pattern);
}
public static TemplatedStruct Templated(char[] pattern)()
{
return TemplatedStruct(pattern);
}
public struct TemplatedStruct
{
const char[] x;
}
void main(char[][] args)
{
TemplatedStruct x = Templated!("123");
auto xCheck = Templated!(x.x);//Causes problems?
auto y = Templated(args[1]);
auto yCheck = Templated(y.x);//OK
//Check if we got the right types...
Stdout("x : ")(typeid(typeof(x))).newline;
Stdout("y : ")(typeid(typeof(y))).newline;
Stdout("--BEGIN--").newline;
Stdout(x.x).newline;
Stdout(y.x).newline;
Stdout("--END--").newline;
}
More information about the Digitalmars-d-learn
mailing list