Saturday 15 March 2014

c++ - Access control to member template functions -


I am working on a project where SFINEE is detected whether a member function exists or not. I am running into a problem with the following example:

  class base {private: template   

The problem is that access control in the base class (such as the private) while trying to use heritage functions is not being respected in the derived category, both Fu and snap-derived Must be inaccessible from the square. So when I try to test that there are some functions in some derived class, then it is using the base class incorrectly to find the match.

In G ++ 4.8.1, both calling Fu and snap are allowed to be wrong, which I am sure is an example of this bug:

In Clag ++ 3.3, the called snarf is properly identified as an error, but foo is allowed to call, it seems that it should also be an error. Does this walking look like a bug in ++? (I have posted a bug report, as it turns out)

Given that it may also be a bug in both compilers, is there a cunning solution that I have been derived, Really have access to foo? The way I'm actually using it is the following:

  template & lt; Square t, square t2, square unused = null & gt; Struct has_member_foo: std :: false_type {};   

Where has_member_foo std :: true_type to declval> T & amp; & Gt; () Is special to call. Foo (declval & lt; t 2 & amp; & gt; ()) resolves a valid function ala; I need this when a derivative class is a personalized version of foo will get.

When you type code, the compiler says which bar

  tries to be called; D.bar & lt; Int & gt; (42);   

If it displays an error, then I think things are working as expected. Unless you actually write code that uses a template method, there is nothing to compile, so if you are using a less intelligent compiler, you will not see any errors coming in it.

You can also define the bar like this:

  template   

and it will still compile (with some compressor), as long as you do not try to use the bar.

No comments:

Post a Comment