www.digitalmars.com         C & C++   DMDScript  

D - template self-instantiation

reply Norbert Nemec <Norbert.Nemec gmx.de> writes:
Help: What am I doing wrong?

----------------------
struct test(T) {
        test!(T) func() {
                test!(T) res;
                return res;
        };
};

int main() {
        test!(int) a;
        a = a.func();
        return 0;
};
----------------------

The gdc tells me
"template instance test!(int) test is not a template declaration"
Apr 24 2004
parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Norbert Nemec" <Norbert.Nemec gmx.de> wrote in message
news:c6dlsg$235$1 digitaldaemon.com...
 Help: What am I doing wrong?

 ----------------------
 struct test(T) {
         test!(T) func() {
                 test!(T) res;
                 return res;
         };
 };
I think that everyone has this problem at first (I did) The solution is very simple: struct test(T) { .test!(T) func() { .test!(T) res; return res; } } The solution is . (gives acces to outer scope) and you don't need ; after struct and function declaration.
 int main() {
         test!(int) a;
         a = a.func();
         return 0;
 };
 ----------------------

 The gdc tells me
 "template instance test!(int) test is not a template declaration"
Apr 24 2004