Hello, good people of the intrawebs!
Today I bring you a bit of a conundrum, namely a structthat makes the linker think it needs an init function.
/**
* Represents a pair of of values of type T.
*/
public struct Pair<T> {
T v0;
T v1;
/**
* Create a Pair with two values.
*/
Pair (T v0, T v1) {
this.v0 = v0; this.v1 = v1;
}
/**
* Create a Pair without any values set
*/
Pair.empty () {}
/**
* Get a value.
*
* @note you should probably not use this as it is slower than using the
* internal values directly.
*/
T @get (size_t index) {
switch (index) {
case 0:
return v0;
case 1:
return v1;
default:
return (T)null;
}
}
/**
* set a value
*
* @note you should probably not use this as it is slower than using the
* internal values directly.
*/
void @set (size_t index, T value) {
switch (index) {
case 0:
this.v0 = value;
break;
case 1:
this.v1 = value;
break;
default:
return;
}
}
}
The compiler compiled that portion fine, but when I try to use it as such:
Pair p = Pair<int> (_height, _width);
I get the following error in the linking stage:
undefined reference to `pair_init'
As I understand it, a struct should not have an init function, so, what is wrong here?
I’ll have a look when I come home, but if it is any help, I’m returning the Pair as an owned object in a property getter. Can it be a problem with that?
Perhaps the code gen does something it should not be doing because of the context?