digitalmars.D.learn - simple struct template
- Hendrik Renken (22/22) Mar 30 2007 Hi,
- Daniel Keep (14/46) Mar 30 2007 alias Vector!(float) Vectorf;
- Hendrik Renken (3/10) Mar 30 2007 dmd on linux32, gdc 0.23 on mac os:
- =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= (14/21) Mar 30 2007 Put your aliases after the struct definition:
- Hendrik Renken (20/36) Mar 30 2007 ah, thanks for your help, now i understand the error message ^^.
- Frits van Bommel (9/30) Mar 30 2007 change that to:
- Hendrik Renken (3/26) Mar 30 2007 *banging the head against the table*
- =?UTF-8?B?SmFyaS1NYXR0aSBNw6RrZWzDpA==?= (4/23) Mar 30 2007 Also I think you can use just Vector instead if Vector!(T) in those
Hi, i've wrote a simple struct template: struct Vector(T) { T x; T y; T z; } now i would like to define some aliases to make my programming life easier: Vectorf for Vector!(float) Vectord for Vector!(double) void main(char[][] args) { Vectorf v; v.x = 0.2f; } is that possible? i tried mixin Vector!(float) Vectorf; alias Vector!(float) Vectorf; with gdc 0.23. both dont work. regards Hendrik
Mar 30 2007
Hendrik Renken wrote:Hi, i've wrote a simple struct template: struct Vector(T) { T x; T y; T z; } now i would like to define some aliases to make my programming life easier: Vectorf for Vector!(float) Vectord for Vector!(double) void main(char[][] args) { Vectorf v; v.x = 0.2f; } is that possible? i tried mixin Vector!(float) Vectorf; alias Vector!(float) Vectorf; with gdc 0.23. both dont work. regards Hendrikalias Vector!(float) Vectorf; alias Vector!(double) Vectord; Should work; if not, what error message is the compiler giving you? -- Daniel -- int getRandomNumber() { return 4; // chosen by fair dice roll. // guaranteed to be random. } http://xkcd.com/ v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
Mar 30 2007
alias Vector!(float) Vectorf; alias Vector!(double) Vectord; Should work; if not, what error message is the compiler giving you? -- Danieldmd on linux32, gdc 0.23 on mac os: "template instance forward reference to template declaration Vector(T)" hendrik
Mar 30 2007
Hendrik Renken wrote:Put your aliases after the struct definition: struct Vector(T) { T x; T y; T z; } alias Vector!(float) Vectorf; void main(char[][] args) { Vectorf v; v.x = 0.2f; }alias Vector!(float) Vectorf; alias Vector!(double) Vectord; Should work; if not, what error message is the compiler giving you?dmd on linux32, gdc 0.23 on mac os: "template instance forward reference to template declaration Vector(T)"
Mar 30 2007
Put your aliases after the struct definition: struct Vector(T) { T x; T y; T z; } alias Vector!(float) Vectorf; void main(char[][] args) { Vectorf v; v.x = 0.2f; }ah, thanks for your help, now i understand the error message ^^. Need to bother you once again. how do i overload opCall, when i want to return the appropriate type, i tried the obvious (at least for me): struct Vector(T) { public: T x, y, z; static Vector!(T) opCall(T x, T y, T z) { this.x, y, z = (x, y, z); } } but then the compiler complains: function Vector.Vector!(float).Vector.opCall expected to return a value of type Vector!(float) where i have defined the aliases. regards, hendrik
Mar 30 2007
Hendrik Renken wrote:how do i overload opCall, when i want to return the appropriate type, i tried the obvious (at least for me): struct Vector(T) { public: T x, y, z; static Vector!(T) opCall(T x, T y, T z) { this.x, y, z = (x, y, z);change that to: Vector!(T) result; result.x = x; result.y = y; result.z = z; return result; Static member function don't _have_ a "this"} } but then the compiler complains: function Vector.Vector!(float).Vector.opCall expected to return a value of type Vector!(float)Because you didn't actually return anything.
Mar 30 2007
Frits van Bommel wrote:Hendrik Renken wrote:*banging the head against the table* seems, as if my brain takes a long nap. sorry for bothering.how do i overload opCall, when i want to return the appropriate type, i tried the obvious (at least for me): struct Vector(T) { public: T x, y, z; static Vector!(T) opCall(T x, T y, T z) { this.x, y, z = (x, y, z);change that to: Vector!(T) result; result.x = x; result.y = y; result.z = z; return result; Static member function don't _have_ a "this" Because you didn't actually return anything.
Mar 30 2007
Frits van Bommel wrote:Hendrik Renken wrote:Also I think you can use just Vector instead if Vector!(T) in those routines. At least it works that way. Those extra letters are sooo expensive.how do i overload opCall, when i want to return the appropriate type, i tried the obvious (at least for me): struct Vector(T) { public: T x, y, z; static Vector!(T) opCall(T x, T y, T z) { this.x, y, z = (x, y, z);change that to: Vector!(T) result; result.x = x; result.y = y; result.z = z; return result;
Mar 30 2007