Why typename can not be inherented from base class?

Discussion in 'C++' started by PengYu.UT@gmail.com, Oct 20, 2005.

  1. Guest

    Hi,

    I'm wondering why typename can not be inherented from base class. An
    example is shown below. If I have to typedef value_type anyway, I think
    it would be easier to define the 5 types in iterator like "typedef T
    value_type" without inherent from std::iterotor.

    Thanks,
    Peng

    #include <iterator>

    template <typename T>
    class iterator : public std::iterator<std::random_access_iterator_tag,
    T> {
    public:
    typedef typename std::iterator<std::random_access_iterator_tag,
    T>::value_type value_type;//this line can not be deleted
    private:
    value_type v;
    };

    int main(){
    iterator<int> it;
    }
     
    , Oct 20, 2005
    #1
    1. Advertising

  2. wrote:
    > I'm wondering why typename can not be inherented from base class. An


    I am not sure what your question is. What can't be inherited?

    template<class T> class Foo {
    public:
    typedef T* pointer;
    };

    template<class T> class Bar : public Foo<T> {
    public:
    typedef typename Foo<T>::pointer pointer; // typedef inherited
    private:
    pointer ptr;
    };

    > example is shown below. If I have to typedef value_type anyway, I
    > think it would be easier to define the 5 types in iterator like
    > "typedef T value_type" without inherent from std::iterotor.


    Easier? In what way?

    > Thanks,
    > Peng
    >
    > #include <iterator>
    >
    > template <typename T>
    > class iterator : public std::iterator<std::random_access_iterator_tag,
    > T> {
    > public:
    > typedef typename std::iterator<std::random_access_iterator_tag,
    > T> value_type value_type;//this line can not be deleted
    > private:
    > value_type v;
    > };
    >
    > int main(){
    > iterator<int> it;
    > }


    V
     
    Victor Bazarov, Oct 20, 2005
    #2
    1. Advertising

  3. Greg Comeau Guest

    In article <>,
    <> wrote:
    >I'm wondering why typename can not be inherented from base class. An
    >example is shown below. If I have to typedef value_type anyway, I think
    >it would be easier to define the 5 types in iterator like "typedef T
    >value_type" without inherent from std::iterotor.
    >
    >#include <iterator>
    >
    >template <typename T>
    >class iterator : public std::iterator<std::random_access_iterator_tag,
    >T> {
    > public:
    > typedef typename std::iterator<std::random_access_iterator_tag,
    >T>::value_type value_type;//this line can not be deleted
    > private:
    > value_type v;
    >};
    >
    >int main(){
    > iterator<int> it;
    >}


    The typename is not being singled out, as there is a more general issue:
    it has to do with names dependent upon the template parameter. See
    http://www.comeaucomputing.com/techtalk/templates/whymembernotfound
    --
    Greg Comeau / Celebrating 20 years of Comeauity!
    Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
    World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
    Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
     
    Greg Comeau, Oct 20, 2005
    #3
  4. Guest

    Greg Comeau wrote:
    > In article <>,
    > <> wrote:
    > >I'm wondering why typename can not be inherented from base class. An
    > >example is shown below. If I have to typedef value_type anyway, I think
    > >it would be easier to define the 5 types in iterator like "typedef T
    > >value_type" without inherent from std::iterotor.
    > >
    > >#include <iterator>
    > >
    > >template <typename T>
    > >class iterator : public std::iterator<std::random_access_iterator_tag,
    > >T> {
    > > public:
    > > typedef typename std::iterator<std::random_access_iterator_tag,
    > >T>::value_type value_type;//this line can not be deleted
    > > private:
    > > value_type v;
    > >};
    > >
    > >int main(){
    > > iterator<int> it;
    > >}

    >
    > The typename is not being singled out, as there is a more general issue:
    > it has to do with names dependent upon the template parameter. See
    > http://www.comeaucomputing.com/techtalk/templates/whymembernotfound


    Sorry, I can't reach this link. Would you please check what is wrong?

    Thanks,
    Peng
     
    , Oct 20, 2005
    #4
  5. Greg Comeau Guest

    In article <>,
    <> wrote:
    >
    >Greg Comeau wrote:
    >> In article <>,
    >> <> wrote:
    >> >I'm wondering why typename can not be inherented from base class. An
    >> >example is shown below. If I have to typedef value_type anyway, I think
    >> >it would be easier to define the 5 types in iterator like "typedef T
    >> >value_type" without inherent from std::iterotor.
    >> >
    >> >#include <iterator>
    >> >
    >> >template <typename T>
    >> >class iterator : public std::iterator<std::random_access_iterator_tag,
    >> >T> {
    >> > public:
    >> > typedef typename std::iterator<std::random_access_iterator_tag,
    >> >T>::value_type value_type;//this line can not be deleted
    >> > private:
    >> > value_type v;
    >> >};
    >> >
    >> >int main(){
    >> > iterator<int> it;
    >> >}

    >>
    >> The typename is not being singled out, as there is a more general issue:
    >> it has to do with names dependent upon the template parameter. See
    >> http://www.comeaucomputing.com/techtalk/templates/whymembernotfound

    >
    >Sorry, I can't reach this link. Would you please check what is wrong?


    http://www.comeaucomputing.com/techtalk/templates/#whymembernotfound
    --
    Greg Comeau / Celebrating 20 years of Comeauity!
    Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
    World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
    Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
     
    Greg Comeau, Oct 20, 2005
    #5
  6. Guest

    Victor Bazarov wrote:
    > wrote:
    > > I'm wondering why typename can not be inherented from base class. An

    >
    > I am not sure what your question is. What can't be inherited?
    >
    > template<class T> class Foo {
    > public:
    > typedef T* pointer;
    > };
    >
    > template<class T> class Bar : public Foo<T> {
    > public:
    > typedef typename Foo<T>::pointer pointer; // typedef inherited

    Why can't I simple delete the above line?

    > private:
    > pointer ptr;
    > };
    >
    > > example is shown below. If I have to typedef value_type anyway, I
    > > think it would be easier to define the 5 types in iterator like
    > > "typedef T value_type" without inherent from std::iterotor.

    >
    > Easier? In what way?

    Since "pointer" in the base class is defined from T anyway, why can't I
    define "pointer" in iterator(my example) without inherent the base
    class std::iterator.
    >
    > > Thanks,
    > > Peng
    > >
    > > #include <iterator>
    > >
    > > template <typename T>
    > > class iterator : public std::iterator<std::random_access_iterator_tag,
    > > T> {
    > > public:
    > > typedef typename std::iterator<std::random_access_iterator_tag,
    > > T> value_type value_type;//this line can not be deleted
    > > private:
    > > value_type v;
    > > };
    > >
    > > int main(){
    > > iterator<int> it;
    > > }
     
    , Oct 20, 2005
    #6
  7. wrote:
    > Victor Bazarov wrote:
    >
    >> wrote:
    >>
    >>>I'm wondering why typename can not be inherented from base class. An

    >>
    >>I am not sure what your question is. What can't be inherited?
    >>
    >> template<class T> class Foo {
    >> public:
    >> typedef T* pointer;
    >> };
    >>
    >> template<class T> class Bar : public Foo<T> {
    >> public:
    >> typedef typename Foo<T>::pointer pointer; // typedef inherited

    >
    > Why can't I simple delete the above line?


    You can't? What gives? Have you tried just deleting it?

    >> private:
    >> pointer ptr;

    ^^^^^^^^^^^^
    And if you delete it, what happens to this line? You may need to change
    it, don't you think?

    >> };
    >>
    >>
    >>>example is shown below. If I have to typedef value_type anyway, I
    >>>think it would be easier to define the 5 types in iterator like
    >>>"typedef T value_type" without inherent from std::iterotor.

    >>
    >>Easier? In what way?

    >
    > Since "pointer" in the base class is defined from T anyway, why can't I
    > define "pointer" in iterator(my example) without inherent the base
    > class std::iterator.


    Can't you?

    V
     
    Victor Bazarov, Oct 20, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rolf Welskes
    Replies:
    2
    Views:
    366
    Rolf Welskes
    Oct 5, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,090
    Smokey Grindel
    Dec 2, 2006
  3. Jakob Bieling

    Q: typename or not typename?

    Jakob Bieling, Mar 14, 2006, in forum: C++
    Replies:
    2
    Views:
    365
    Rolf Magnus
    Mar 14, 2006
  4. Replies:
    9
    Views:
    413
    Daniel T.
    Oct 17, 2006
  5. yanni
    Replies:
    1
    Views:
    781
    Alexey Smirnov
    Nov 9, 2008
Loading...

Share This Page