Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
January 15, 2004 [Bug] struct template type error | ||||
---|---|---|---|---|
| ||||
The following code snippit generated this error: err.d(9): Foo is used as a type struct Foo(T) { T x = 0; static Foo bar(T c1) { Foo rtn; // Error here rtn.x = c1; return rtn; } } void func() { alias Foo!(double) vector; vector xAxis = vector.bar(1); } |
January 15, 2004 Re: [Bug] struct template type error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Patrick Down | struct Foo(T) { T x = 0; static Foo bar(T c1) { Foo !(double) rtn; // must instantiate with type rtn.x = c1; return rtn; } } void func() { alias Foo!(double) vector; vector xAxis = vector.bar(1); } Howerver if use T to instatiate Foo , I get identifier 'T' is not defined Changing the code to ============== struct Foo(T) { T x = 0; static Foo bar(T c1) { Foo !(typeof(c1) ) rtn; // must instantiate with type rtn.x = c1; return rtn; } } void func() { alias Foo!(double) vector; vector xAxis = vector.bar(1); } void main () { func(); } Works and is probably what you want ? C C void main () { func(); } "Patrick Down" <pat@codemoon.com> wrote in message news:Xns9470D8C2F1A87patcodemooncom@63.105.9.61... > > The following code snippit generated this error: > err.d(9): Foo is used as a type > > struct Foo(T) > { > T x = 0; > > static Foo bar(T c1) > { > Foo rtn; // Error here > rtn.x = c1; > return rtn; > } > } > > void func() > { > alias Foo!(double) vector; > > vector xAxis = vector.bar(1); > } |
January 15, 2004 Re: [Bug] struct template type error | ||||
---|---|---|---|---|
| ||||
Posted in reply to C | Chaing bar to be a non-static method T is still an undefined identifier , why is that ? C "C" <dont@respond.com> wrote in message news:bu51u2$boo$1@digitaldaemon.com... > struct Foo(T) > { > T x = 0; > > static Foo bar(T c1) > { > Foo !(double) rtn; // must instantiate with type > rtn.x = c1; > return rtn; > } > } > > void func() > { > alias Foo!(double) vector; > vector xAxis = vector.bar(1); > } > > Howerver if use T to instatiate Foo , I get > > identifier 'T' is not defined > > Changing the code to > ============== > > struct Foo(T) > { > T x = 0; > > static Foo bar(T c1) > { > Foo !(typeof(c1) ) rtn; // must instantiate with type > rtn.x = c1; > return rtn; > } > } > > void func() > { > alias Foo!(double) vector; > vector xAxis = vector.bar(1); > } > > void main () { func(); } > > Works and is probably what you want ? > > C > > > > C > > void main () { func(); } > "Patrick Down" <pat@codemoon.com> wrote in message > news:Xns9470D8C2F1A87patcodemooncom@63.105.9.61... > > > > The following code snippit generated this error: > > err.d(9): Foo is used as a type > > > > struct Foo(T) > > { > > T x = 0; > > > > static Foo bar(T c1) > > { > > Foo rtn; // Error here > > rtn.x = c1; > > return rtn; > > } > > } > > > > void func() > > { > > alias Foo!(double) vector; > > > > vector xAxis = vector.bar(1); > > } > > |
January 15, 2004 Re: [Bug] struct template type error | ||||
---|---|---|---|---|
| ||||
Posted in reply to C | inline "C" <dont@respond.com> wrote in news:bu51u2$boo$1@digitaldaemon.com: > struct Foo(T) > { > T x = 0; > > static Foo bar(T c1) > { > Foo !(double) rtn; // must instantiate with type > rtn.x = c1; > return rtn; > } > } > > void func() > { > alias Foo!(double) vector; > vector xAxis = vector.bar(1); > } > > Howerver if use T to instatiate Foo , I get > > identifier 'T' is not defined Yeah I had the same problem. Foo!(T) rtn; should work. I think this is the real bug. > > Changing the code to > ============== > > struct Foo(T) > { > T x = 0; > > static Foo bar(T c1) > { > Foo !(typeof(c1) ) rtn; // must instantiate with type > rtn.x = c1; > return rtn; > } > } > > void func() > { > alias Foo!(double) vector; > vector xAxis = vector.bar(1); > } > > void main () { func(); } > > Works and is probably what you want ? > > C Yes that works, Thanks. > > > > C > > void main () { func(); } > "Patrick Down" <pat@codemoon.com> wrote in message > news:Xns9470D8C2F1A87patcodemooncom@63.105.9.61... >> >> The following code snippit generated this error: >> err.d(9): Foo is used as a type >> >> struct Foo(T) >> { >> T x = 0; >> >> static Foo bar(T c1) >> { >> Foo rtn; // Error here >> rtn.x = c1; >> return rtn; >> } >> } >> >> void func() >> { >> alias Foo!(double) vector; >> >> vector xAxis = vector.bar(1); >> } > > |
January 15, 2004 Re: [Bug] struct template type error | ||||
---|---|---|---|---|
| ||||
Posted in reply to C | This give me the error: template instance Foo!(double) Foo is not a template declaration struct Foo(T) { T x = 0; static Foo!(T) bar(T c1) { Foo!(typeof(c1)) rtn; rtn.x = c1; return rtn; } } void func() { alias Foo!(double) vector; vector xAxis = vector.bar(1); } void main () { func(); } "C" <dont@respond.com> wrote in news:bu51u2$boo$1@digitaldaemon.com: > struct Foo(T) > { > T x = 0; > > static Foo bar(T c1) > { > Foo !(double) rtn; // must instantiate with type > rtn.x = c1; > return rtn; > } > } > > void func() > { > alias Foo!(double) vector; > vector xAxis = vector.bar(1); > } > > Howerver if use T to instatiate Foo , I get > > identifier 'T' is not defined > > Changing the code to > ============== > > struct Foo(T) > { > T x = 0; > > static Foo bar(T c1) > { > Foo !(typeof(c1) ) rtn; // must instantiate with type > rtn.x = c1; > return rtn; > } > } > > void func() > { > alias Foo!(double) vector; > vector xAxis = vector.bar(1); > } > > void main () { func(); } > > Works and is probably what you want ? > > C > > > > C > > void main () { func(); } > "Patrick Down" <pat@codemoon.com> wrote in message > news:Xns9470D8C2F1A87patcodemooncom@63.105.9.61... >> >> The following code snippit generated this error: >> err.d(9): Foo is used as a type >> >> struct Foo(T) >> { >> T x = 0; >> >> static Foo bar(T c1) >> { >> Foo rtn; // Error here >> rtn.x = c1; >> return rtn; >> } >> } >> >> void func() >> { >> alias Foo!(double) vector; >> >> vector xAxis = vector.bar(1); >> } > > |
Copyright © 1999-2021 by the D Language Foundation