Victor Bazarov wrote in
No, this is not allowed. Only addresses of objects with external
linkage are allowed. You're trying to use a _pointer_to_member_
expression where a pointer to int is expected, and also (while
incorrectly syntactically) you're trying to use an address of an
object that has no linkage (a data member has no linkage if it's
non-static).
#include <iostream>
#include <ostream>
template < typename T, typename C, T C::*member >
struct X
{
static T test( C * c) { return c->*member; }
};
struct Y
{
int p;
};
typedef X< int, Y, &Y:
> XY;
template < char * p >
struct PP
{
char a() { return *p; }
};
char array[1] = {'a'};
typedef PP< array > PP_array;
int main()
{
using namespace std;
Y y = { 10 };
cerr << XY::test( &y ) << '\n';
cerr << PP_array().a() << '\n';
}
IIUC all that matters here is that Y has external linkage.
i.e. &Y:
is a constant whose value is unique as its based upon
Y's external linkage.
I think something similar goes on above with PP, PP's paramiter p
is a char * const that is unique in that it is based on array a
char [1] with external linkage.
Rob.