Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 0.57 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // % cat foo.cpp
  2.  
  3. #if USE_TEMPLATES == 0
  4. class A { protected: void f() {} };
  5. class B : public A { using A::f; };
  6. int main() { B b; b.f(); }
  7. #else
  8. template<int AI> class A { protected: void f() {} };
  9. template<int BI> class B : public A<BI> { using A<BI>::f; };
  10. int main() { B<3> b; b.f(); }
  11. #endif
  12.  
  13. // % g++ -DUSE_TEMPLATES=1 -o foo foo.cpp
  14. // % ./foo                              
  15.  
  16. // % g++ -DUSE_TEMPLATES=0 -o foo foo.cpp
  17. // foo.cpp: In function ‘int main()’:
  18. // foo.cpp:2: error: ‘void A::f()’ is protected
  19. // foo.cpp:4: error: within this context