Advertisement

workaround for invalid C2247 error

Started by March 29, 2018 04:46 PM
10 comments, last by Alberth 6 years, 5 months ago
4 hours ago, tanzanite7 said:

No. It (Bar) should not try to access a member it should not even know exists (in Foo) and use the variable in global scope it does see and as far as implementer of Bar is concerned - is the only one the implementer can be reasonably expected to know about.

If you provide a class definition with the data member in a .h file, the information is available, ie humans can open the .h file and read.

The compiler is just relaying that information, it's not giving information that cannot be found by other means already.

 

If you are so paranoid about exposing internal implementation details, don't expose it; make a strict separation between public members that is in a public .h file, and internal data, which is never published, but can eg be added using a separate impl object.

 

Of course, all the above doesn't mean much at all. There is no such thing as "not accessible" in run-time. Just because the compiler does give me access doesn't mean I cannot setup a pointer to the field with a base address and an offset, with a static cast to the right type, et voila, I have your "not available" data (and I can even write in it through the pointer). It takes a bit of knowledge what offset to use, but compilers are not very mysterious in how they layout fields in a class.

This topic is closed to new replies.

Advertisement