Why can't I use alias from a base class in a derived class with templates?

后端 未结 3 1897
Happy的楠姐
Happy的楠姐 2021-01-20 23:37

Consider this C++ code :

template
class Step
{
public:
   using Session_ptr = boost::shared_ptr;
protected:
   Session_pt         


        
3条回答
  •  渐次进展
    2021-01-21 00:36

    Here I give another example with the solutions already given in other answers presented.

    std::iterator is a dependent base class of Myterator. In order to lookup there, you'll have to do qualified name lookup.

    // std::iterator example  from http://www.cplusplus.com/reference/iterator/iterator/
    //***************************************************************************************
    #include      // std::cout
    #include      // std::iterator, std::input_iterator_tag
    
    template 
    class MyIterator : public std::iterator
    {
      // The working alternatives, one per row
      //typename std::iterator::pointer  p;
      //using pointer = typename std::iterator::pointer; pointer p;
      //using typename std::iterator::pointer; pointer p;
      //using Iter = typename std::iterator; typename Iter::pointer p;
      pointer p; // This does not work while any of alternatives in comments above do work
    public:
      MyIterator(MyType* x) :p(x) {}
      MyType& operator*() {return *p;}
    
    };
    
    int main () {
      int numbers[]={10,20,30,40,50};
      MyIterator from(numbers);
      std::cout << *from << ' ';
      std::cout << '\n';
    
      return 0;
    }
    

提交回复
热议问题