Topic: implicit template argument
Author: fwai@armltd.co.uk (Francis Wai)
Date: 1996/09/26 Raw View
dzaak@fm.bs.dlr.de (Frank Dzaak) writes:
>I would like to know whether a template argument has to be supplied
>for an argument typ in a member function or not. Which of the two
>version is correct?
> #include <iostream.h>
> #include <stdio.h>
>
> template<class T>
> class A {
> T e;
> A<T> *a;
> public:
> A(const T& i) { e=i; a=NULL; }
>either
> A(const T& i, A& r) { e=i; a=&r; }
>or
> A(const T& i, A<T>& r) { e=i; a=&r; }
They mean the same. Both should be accepted by the compiler. However, ...
> };
>
> int main()
> {
> int i=2;
> A<float> a(i);
> A<int> b(i, a);
> }
Your example is flaw. 'a' has type A<float>. The arg 'r' in the two-arg
constructor has the same type as the specialised class which in the
example is A<int>.
--Francis
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1996/09/27 Raw View
>>>>> In article <DyA6x7.JoJ@news.dlr.de>, dzaak@fm.bs.dlr.de (Frank
>>>>> Dzaak) writes:
> Dear C++ Experts,
> I would like to know whether a template argument has to be supplied
> for an argument typ in a member function or not. Which of the two
> version is correct?
> template<class T>
> class A {
> public:
> either
> A(const T& i, A& r) { e=i; a=&r; }
> or
> A(const T& i, A<T>& r) { e=i; a=&r; }
> };
Both. If A<T> is equivalent to A inside A<T> definition.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br
Universidade Estadual de Campinas, SP, Brasil
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: dzaak@fm.bs.dlr.de (Frank Dzaak)
Date: 1996/09/25 Raw View
Dear C++ Experts,
I would like to know whether a template argument has to be supplied
for an argument typ in a member function or not. Which of the two
version is correct?
#include <iostream.h>
#include <stdio.h>
template<class T>
class A {
T e;
A<T> *a;
public:
A(const T& i) { e=i; a=NULL; }
either
A(const T& i, A& r) { e=i; a=&r; }
or
A(const T& i, A<T>& r) { e=i; a=&r; }
};
int main()
{
int i=2;
A<float> a(i);
A<int> b(i, a);
}
Mit freundlichen Gruessen Frank Dzaak.
_______________________________________________________________________________
Deutsche Forschungsanstalt fuer Luft- und Raumfahrt e.V.
Institut fuer Flugmechanik
Frank Dzaak
Postfach 32 67 Tel: +49 531 295 2706
38022 Braunschweig Fax: +49 531 295 2877
Deutschland Email: dzaak@fm.bs.dlr.de
_______________________________________________________________________________
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]