C++ private inheritance and static members/types -


I am trying to prevent a class from being able to change my 'this' pointer to an indicator of one of my interfaces. I am here. I do this by using a private heritage through a middle proxy class. The problem is that I believe that all public static members in the private heritage and type of base class are not accessible to all classes under the inheritance class in the hierarchy.

  class base {public: enum enum {value}; }; Square middle: private base {}; Class Child: Public Middle {Public: Zero Law () {Base :: Enum E = Base :: Value; // does not compile BAD! Base * base = this; // does not compile well! }};  

I tried to use it both in VS2008 (required version) and VS2010, neither work.

Can anyone think of an alternate solution? Or is there a different way to stop conversion?

In addition to this, I am curious of behavior, is it just a side effect of the compiler implementation, or is it by design? If from design, then why? I was always thinking about personal heritage that no one knows the middle heritage from the base. However, the behavior shown is that the meaning of private heritage is much higher than that, in fact the child does not have access to less than any namespace in the class post.

You can fully qualify it by reaching Base :: Enum Should be enabled:

  class child: public middle {public: zero method () {: base :: enum e = :: base :: value; }};  

This behavior is specified by the language (C ++ 03 § 11.2 / 3):

Note: A member of a private base class may be a The hereditary member is not accessible as a name, but is directly accessible.

Thereafter, a detailed example is given that is very similar to your example code.

However, it appears that no visible C ++ 2008 nor Visual C ++ 2010 appropriately applies it, so when you use :: Base :: Enum < / Code>, you can still use the :: Base :: value . (In fact, Visual C ++ is very wrong, because it incorrectly allows you to use Base :: Enum ).

"Go" around the problem, you can use announcements in the middle class:

  class middle: private base {protected : Base: Using Anem; Base :: Using the value; };  

This will not allow you to use the Base :: Enum or base :: value in your child Class, but it should use you to use Enum and value or middle :: enum and middle :: value will allow. Code>.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -