Topic: Typename, ANSI/C++ and aCC


Author: Stefan Lecho <stlecho@vub.ac.be>
Date: 1999/04/22
Raw View
This is a multi-part message in MIME format.
--------------30AF5BC1E7F4A7596BF35833
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

[ Don't post MIME encoded messages please --mod ]

I am currently testing the aCC compiler of HP and involved into a -
endless - discussion with the support team concerning the use of
typenames.

The following class structure is used :
#include <vector>
template <class T>
class A : public vector<T> {
public:
    A( size_type sz) : vector<T>(sz)    {}
    void remove( const T& item) { erase(find(begin(),end(),item)); }
};

When the above code is compiled with the HP aCC compiler - options :
"+inst_auto +inst_v -DDEBUG -DANSI_CPP +p" - the following errors are
generated :
1/ "'size_type' is used as a type, but has not been defined as a type."
2/ Undeclared variable 'end'. Did you forget to make the variable
dependent on the template type parameters so it would be looked up when
templates are generated?

When I correct the above code to produce the code beneath, the class
compiles correctly :
#include <vector>
template <class T>
class A : public vector<T> {
public:
    A( typename vector<T>::size_type sz) : vector<T>(sz)    {}
    void remove( const T& item) {
erase(find(vector<T>::begin(),vector<T>::end(),item)); }
};

My questions are the following :
1/ Why do I have to use "typename vector<T>::size_type" when the
size_type is defined in the vector base class ?
2/ Why do I have to use "vector<T>::begin()" when the begin() method is
declared in the vector base class ?
3/ Why don't I have to use "vector<T>::find(...)" if I am forced to use
vector<T>::begin() ? Who is consequent ?
4/ The HP support team arguments that the above corrections are forced
by the latest ANSI/C++ standard.  Is this true ?

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stefan LECHO                            Software Engineer
VUB - TW/ETEC        Computational Electrochemistry Group
http://wwwtw.vub.ac.be/ond/etec/ceg/english/stef/stef.htm



--------------30AF5BC1E7F4A7596BF35833
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Stefan Lecho
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Stefan Lecho
n:              Lecho;Stefan
org:            VUB TW/ETEC
adr:            Pleinlaan 2;;;Brussel;;1050;Belgium
email;internet: stlecho@vub.ac.be
title:          Software Engineer
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
version:        2.1
end:            vcard


--------------30AF5BC1E7F4A7596BF35833--
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/04/22
Raw View
Stefan Lecho wrote:

> I am currently testing the aCC compiler of HP and involved into a -
> endless - discussion with the support team concerning the use of
> typenames.
>
> The following class structure is used :
> #include <vector>
> template <class T>
> class A : public vector<T> {
> public:
>     A( size_type sz) : vector<T>(sz)    {}
>     void remove( const T& item) { erase(find(begin(),end(),item)); }
> };
>
> When the above code is compiled with the HP aCC compiler - options :
> "+inst_auto +inst_v -DDEBUG -DANSI_CPP +p" - the following errors are
> generated :
> 1/ "'size_type' is used as a type, but has not been defined as a type."

This is correct

> 2/ Undeclared variable 'end'. Did you forget to make the variable
> dependent on the template type parameters so it would be looked up when
> templates are generated?

Also correct

> My questions are the following :
> 1/ Why do I have to use "typename vector<T>::size_type" when the
> size_type is defined in the vector base class ?

because base classes depending on the template arguments (here
depending on T) aren't considered for unqualified name lookup

> 2/ Why do I have to use "vector<T>::begin()" when the begin() method is
> declared in the vector base class ?

Same reason

> 3/ Why don't I have to use "vector<T>::find(...)" if I am forced to use
> vector<T>::begin() ? Who is consequent ?

Because there is no such thing a vector<T>::find(...), only std::find.

> 4/ The HP support team arguments that the above corrections are forced
> by the latest ANSI/C++ standard.  Is this true ?

This is correct

--

Valentin Bonnard


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]