fork(6) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template< typename LeafT>
  5. class ATree {
  6. public:
  7. virtual ATree< LeafT> * branch() = 0;
  8. };
  9.  
  10. template< typename LeafT, typename Self>
  11. class Tree : public ATree< LeafT> {
  12. public:
  13. Self * branch() {}
  14. };
  15.  
  16. template< typename LeafT>
  17. class C : public Tree< LeafT, C< LeafT> > {};
  18.  
  19. int main() {
  20. C< int> t;
  21.  
  22. return 0;
  23. }
Compilation error #stdin compilation error #stdout 0s 3136KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'class Tree<int, C<int> >':
prog.cpp:17:11:   required from 'class C<int>'
prog.cpp:20:10:   required from here
prog.cpp:13:16: error: invalid covariant return type for 'Self* Tree<LeafT, Self>::branch() [with LeafT = int; Self = C<int>]'
         Self * branch() {}
                ^
prog.cpp:7:34: error:   overriding 'ATree<LeafT>* ATree<LeafT>::branch() [with LeafT = int]'
         virtual  ATree< LeafT> * branch() = 0;
                                  ^
stdout
Standard output is empty