Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Why typename can not be inherented from base class?

Reply
Thread Tools

Why typename can not be inherented from base class?

 
 
PengYu.UT@gmail.com
Guest
Posts: n/a
 
      10-20-2005
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;
}

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      10-20-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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>:ointer 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


 
Reply With Quote
 
 
 
 
Greg Comeau
Guest
Posts: n/a
 
      10-20-2005
In article <(E-Mail Removed) .com>,
(E-Mail Removed) <(E-Mail Removed)> 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/techt...membernotfound
--
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?
 
Reply With Quote
 
PengYu.UT@gmail.com
Guest
Posts: n/a
 
      10-20-2005

Greg Comeau wrote:
> In article <(E-Mail Removed) .com>,
> (E-Mail Removed) <(E-Mail Removed)> 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/techt...membernotfound


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

Thanks,
Peng

 
Reply With Quote
 
Greg Comeau
Guest
Posts: n/a
 
      10-20-2005
In article <(E-Mail Removed) .com>,
(E-Mail Removed) <(E-Mail Removed)> wrote:
>
>Greg Comeau wrote:
>> In article <(E-Mail Removed) .com>,
>> (E-Mail Removed) <(E-Mail Removed)> 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/techt...membernotfound

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


http://www.comeaucomputing.com/techt...membernotfound
--
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?
 
Reply With Quote
 
PengYu.UT@gmail.com
Guest
Posts: n/a
 
      10-20-2005

Victor Bazarov wrote:
> (E-Mail Removed) 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>:ointer 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;
> > }


 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      10-20-2005
(E-Mail Removed) wrote:
> Victor Bazarov wrote:
>
>>(E-Mail Removed) 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>:ointer 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
 
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
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
How to make the public inherented member function private or protected? PengYu.UT@gmail.com C++ 9 10-17-2006 12:01 PM
CustomControls inherented from CompositeControl allways have as tag span - how to change this Rolf Welskes ASP .Net 2 10-05-2006 12:56 PM
Q: typename or not typename? Jakob Bieling C++ 2 03-14-2006 03:44 PM
Why can't I use vector<T1>::size_type where T1 is a template typename? Eric Lilja C++ 3 04-23-2005 01:25 PM



Advertisments