Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Accessing types in base class?

Reply
Thread Tools

Accessing types in base class?

 
 
none
Guest
Posts: n/a
 
      03-27-2010
I have this base class:


template<typename J>
class Processor {
public:
const unsigned int Dimension = J:imension;
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?
 
Reply With Quote
 
 
 
 
Abhishek Padmanabh
Guest
Posts: n/a
 
      03-27-2010

"none" <""mort\"@(none)"> wrote in message
news:4badd7b4$0$281$(E-Mail Removed)...
> I have this base class:
>
>
> template<typename J>
> class Processor {
> public:
> const unsigned int Dimension = J:imension;
> 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:imension;
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
}
};



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Containg Types Or Base Types rn5a@rediffmail.com ASP .Net 0 11-22-2006 10:18 PM
accessing base class members when base is template flopbucket C++ 2 06-23-2006 01:40 AM
Format of compiler generated derived destructor when base has 'virtual ~base() throw():" qazmlp C++ 1 04-10-2005 03:09 PM
Virtual function 'BasicMidReader::~BasicMidReader()' conflicts with base class 'base 'TMemoryStream' tomek C++ 2 12-01-2003 06:31 AM
Virtual function 'BasicMidReader::~BasicMidReader()' conflicts with base class 'base 'TMemoryStream' tomek C++ 3 11-30-2003 12:18 AM



Advertisments