How to reference a data field of a parent template class

Discussion in 'C++' started by Xin Wang, Apr 4, 2005.

  1. Xin Wang

    Xin Wang Guest

    In ansi c++, you can do something like
    template <class T>
    class vector<T>
    {
    protected:
    int a;
    int b;
    }

    class boundedVector<T> : public vector<T>
    {
    protected:
    int c;
    }

    And you can use the fields of vector as if they are defined for
    boundedVector, but these are no longer allowed by ansi, right?

    Xin Wang
     
    Xin Wang, Apr 4, 2005
    #1
    1. Advertising

  2. Xin Wang

    David White Guest

    "Xin Wang" <> wrote in message
    news:p...
    >
    > In ansi c++, you can do something like
    > template <class T>
    > class vector<T>
    > {
    > protected:
    > int a;
    > int b;
    > }


    Missing semi-colon.

    > class boundedVector<T> : public vector<T>
    > {
    > protected:
    > int c;
    > }


    Missing semi-colon.

    > And you can use the fields of vector as if they are defined for
    > boundedVector, but these are no longer allowed by ansi, right?


    I don't understand your question. Under what circumstances do you mean "use
    the fields of vector as if they are defined for boundedVector"? A
    boundedVector<T> inherits the members of vector<T>. It has always been the
    case, and remains so, that a class inherits the members of its base
    class(es), if any. Is that what you are asking about?

    DW
     
    David White, Apr 4, 2005
    #2
    1. Advertising

  3. Xin Wang

    Sumit Rajan Guest

    Xin Wang wrote:
    > In ansi c++, you can do something like
    > template <class T>
    > class vector<T>
    > {
    > protected:
    > int a;
    > int b;
    > }
    >
    > class boundedVector<T> : public vector<T>
    > {
    > protected:
    > int c;
    > }
    >
    > And you can use the fields of vector as if they are defined for
    > boundedVector, but these are no longer allowed by ansi, right?



    I hope this helps:
    http://parashift.com/c -faq-lite/templates.html#faq-35.12

    Regards,
    Sumit.
    --
    Sumit Rajan <>
     
    Sumit Rajan, Apr 4, 2005
    #3
    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. Roy
    Replies:
    2
    Views:
    3,170
  2. Grey Plastic
    Replies:
    4
    Views:
    842
    pw4getter
    Mar 5, 2004
  3. christopher diggins
    Replies:
    16
    Views:
    784
    Pete Becker
    May 4, 2005
  4. A L
    Replies:
    1
    Views:
    530
    Alf P. Steinbach /Usenet
    Aug 25, 2010
  5. Sound
    Replies:
    2
    Views:
    498
    Randy Webb
    Sep 28, 2006
Loading...

Share This Page