Can we have an anonymous struct as template argument?
- by nonoitall
The title is pretty self-explanatory, but here's a simplified example:
#include <cstdio>
template <typename T>
struct MyTemplate {
T member;
void printMemberSize() {
printf("%i\n", sizeof(T));
}
};
int main() {
MyTemplate<struct { int a; int b; }> t; // <-- compiler doesn't like this
t.printMemberSize();
return 0;
}
The compiler complains when I try to use an anonymous struct as a template argument. What's the best way to achieve something like this without having to have a separate, named struct definition?