Accessing types in base class?

Discussion in 'C++' started by none, Mar 27, 2010.

  1. none

    none Guest

    I have this base class:


    template<typename J>
    class Processor {
    public:
    const unsigned int Dimension = J::Dimension;
    typedef typename J::ImageType ImageType;

    Processor ();
    virtual ~Processor ();

    };
    #endif


    In a sub class I need to use the types from the base class:


    template <typename J>
    class SubProcessor : public Processor<J>{
    public:

    void test(ImageType image) {
    // do stuff

    }

    };

    But that is not possible! The base class type "ImageType" is not visible in the sub class. In the
    sub class I could just do the same as in the base class:

    typedef typename J::ImageType ImageType;

    but what is the point of using inheritance then?
     
    none, Mar 27, 2010
    #1
    1. Advertising

  2. "none" <""mort\"@(none)"> wrote in message
    news:4badd7b4$0$281$...
    > I have this base class:
    >
    >
    > template<typename J>
    > class Processor {
    > public:
    > const unsigned int Dimension = J::Dimension;
    > typedef typename J::ImageType ImageType;
    >
    > Processor ();
    > virtual ~Processor ();
    >
    > };
    > #endif
    >
    >
    > In a sub class I need to use the types from the base class:
    >
    >
    > template <typename J>
    > class SubProcessor : public Processor<J>{
    > public:
    >
    > void test(ImageType image) {
    > // do stuff
    >
    > }
    >
    > };
    >
    > But that is not possible! The base class type "ImageType" is not visible
    > in the sub class. In the sub class I could just do the same as in the base
    > class:
    >
    > typedef typename J::ImageType ImageType;
    >
    > but what is the point of using inheritance then?


    You would need to do something like this, although the initialization of the
    const member in the base class is not valid, (and hence commented out):

    template<typename J>
    class Processor
    {
    public:
    //const unsigned int Dimension = J::Dimension;
    typedef typename J::ImageType ImageType;
    Processor ();
    virtual ~Processor ();
    };
    template <typename J>
    class SubProcessor : public Processor<J>
    {
    public:
    void test(typename Processor<J>::ImageType image) {
    // do stuff
    }
    };
     
    Abhishek Padmanabh, Mar 27, 2010
    #2
    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. Replies:
    0
    Views:
    399
  2. Alf P. Steinbach
    Replies:
    6
    Views:
    558
    John Carson
    Sep 3, 2005
  3. flopbucket
    Replies:
    2
    Views:
    435
    Andrey Tarasevich
    Jun 23, 2006
  4. Hicham Mouline
    Replies:
    1
    Views:
    604
    Victor Bazarov
    Apr 20, 2009
  5. Karan Rajput
    Replies:
    2
    Views:
    150
    Abinoam Jr.
    Dec 22, 2010
Loading...

Share This Page