Closed goretkin closed 5 years ago
For a concrete example
using Cxx
cxx"""
class WithProtected
{
protected:
int m_private;
public:
int m_public;
};
"""
class = @cxxnew WithProtected()
@show icxx"$(class)->m_public;"
@show icxx"$(class)->m_private;"
julia> include("cxx_private.jl")
#= /Users/goretkin/projects/Bullet/cxx_private.jl:14 =# @icxx_str("\$(class)->m_public;") = 0
In file included from /Cxx.cpp:1:
/Users/goretkin/projects/Bullet/cxx_private.jl:15:14: error: 'm_private' is a protected member of 'WithProtected'
__juliavar1->m_private;
^
/Users/goretkin/projects/Bullet/cxx_private.jl:6:9: note: declared protected here
int m_private;
^
#= /Users/goretkin/projects/Bullet/cxx_private.jl:15 =# @icxx_str("\$(class)->m_private;") = 0
0
Is there a way to use Cxx to access private members of a class? I believe there are hacks to do this in C++, but as far as I know they are all undefined behavior. Can Cxx know the memory layout of a class's private members?