ENIGMA Forums
General fluff => Off-Topic => Topic started by: Ideka on September 26, 2013, 11:53:07 pm
-
template <class T, class U> class SomeClass {
public:
// ...
U some_method() {
// ...
}
}
class OtherClass : public SomeClass<YetAnotherClass, OtherClass> { // !!!
public:
// ...
}
So it's a class that inherits from a template of another class and itself, so it can later return its own type. I couldn't believe it but it even works and everything.
And...
Yeah...
That's it.
-
Your compiler did not blow up? I do not see why this would even be useful.
-
Hai Ideka, long time no see :) Sorry if I am being lazy responding to you guys today.
-
Hai Robert :P.
@DaSpirit: Here's more context so you see why I had to do it:
template <class T, class U> class Image {
public:
// ...
U cropping(int x, int y, uint width, uint height) {
// ...
}
// ...
protected:
std::vector<std::vector<T> > grid;
}
class Surface : public Image<Tile, Surface> {
// ...
}
class Layer : public Image<MapFeature, Layer> {
// ...
}
If you think there's a better way of doing this I'm all ears.
-
I don't see why you made them need each other. So a surface always has one other surface? Doesn't make much sense to me.
-
It doesnt have a surface, it can return a surface (or rather, it can have its parent return a surface).
BTW turns out, this is actually a pattern: http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern (http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). Guess it's not that crazy after all.