What is wrong with the following piece of code?
#include
template
struct A {
struct X { K p; };
struct Y { K q; }
Firstly, using :: for referencing a nested struct is not correct. The right way is to use A, where x is a member of type X. But for this to work, you need to declare two members x, y of type X and Y, respectively.
Secondly, I think that a good practice is to separate the template declarations of struct X and struct Y from the declaration of struct A in order to avoid the nested struct declaration.
In short, I would rewrite your code as followings:
template
struct X {
K p;
};
template
struct Y {
K q;
};
template
struct A {
X x;
Y y;
};
template
void foo(const X& x, const Y& y) {
std::cout << "A" << std::endl;
}
int main() {
A a;
foo(a.x, a.y);
return 0;
}