Re: Alternative to virtual template function
Lourens Veen ha scritto:
Why not make the IPlatform implementation a template parameter to
Application? In essence, you'd have a "platform connector" policy.
struct Unix {
static int function() {
// UNIX implementation
}
};
struct Windows {
static int function() {
// Windows implementation
}
};
template <class Platform>
struct Application {
Application() : x(Platform::function()) {}
private:
int x;
}
I still prefer the approach I described in my previous post. I don't see
the advantage of having the application depend explicitly on the
platform. Oppositely, with this approach every file in your program will
need to include the whole platform layer implementation and not only the
interface. If the layer is big, compile time is going to be an issue.
I'm using this construct all over the place in the research prototype
I'm developing. It makes it very easy to change things about and try
out new ideas.
In the preliminary stages of the design, I agree that it might be
useful. However, the platform layer interface usually solidify quite
early during the life-cycle of a cross-platform project so I expect the
interface not to change very often. With your approach, each time you
change something in the implementation you need to recompile the whole
project, while my approach you just compile the changed cpp file and relink.
Frankly, I don't recommend your approach except for very small projects.
Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]