Skip to content

Access to a private reference? #12

@blackbox-tech

Description

@blackbox-tech

Awesome little header, is there a way to access a private member that is a reference?

It's not listed as a limitation, but I could not find a test for it.

I did some experiments in g++ but I got some compilation errors, for example:

struct A {
public:
    A() : foo(99), bar(foo) {}
private:
    int foo;
    int& bar;
};

ACCESS_PRIVATE_FIELD(A, int, bar)  // error: cannot create pointer to reference member
ACCESS_PRIVATE_FIELD(A, int&, bar) // error: cannot declare pointer to 'using Alias_PrivateAccessTag0 = int&' {aka 'int&'}

int& x = access_private::bar(a);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions