Topic: Explicit template parameters on construction
Author: Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
Date: 2000/07/11 Raw View
James Kuyper <kuyper@wizard.net> writes:
[...]
| See section 14.5.2p5. The note points out that "because the explicit
| template argument list follows the function template name, and because
| conversion member function templates and construction member function
| templates are called without using a function name, there is no way to
| provide an explicit template argument list for these function
| templates." Notes are not normative, but this one is merely putting
| together the consequences of normative wording elsewhere in the
| standard.
Constructors don't have names (12.1/1).
--
Gabriel Dos Reis, dosreis@cmla.ens-cachan.fr
---
[ 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: Hyman Rosen <hymie@prolifics.com>
Date: 2000/07/11 Raw View
"HT" <ht@labyrinth.net.au> writes:
> You cannot template class like that.
He's trying to template the cosntructor, not the class.
---
[ 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: Hyman Rosen <hymie@prolifics.com>
Date: 2000/07/09 Raw View
Christopher Eltschka <celtschk@physik.tu-muenchen.de> writes:
> Assuming I have the following class:
>
> struct A { template<class T> A(); };
>
> and now I want to declare an object using A::A<double>().
> What is the correct way?
There is none. All template paramaters of a templated constructor
must be deducible. There is no way of specifying them directly.
This is explicitly stated in 14.8.1/5.
---
[ 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: James Kuyper <kuyper@wizard.net>
Date: 2000/07/09 Raw View
Christopher Eltschka wrote:
>
> Assuming I have the following class:
>
> class A
> {
> public:
> template<class T> A();
> };
>
> and now I want to declare an object using A::A<double>().
> What is the correct way?
>
> Some tries, and what g++ tells me:
>
> A<double> a; // "non-template type `A' used as a template"
> A a<double>; // g++ doesn't complain about the <double>,
> // but claims there's no A::A() it could use.
> // So, is this correct syntax and compiler bug,
> // or wrong syntax and misleading message?
> A a(A<double>()); // "non-template type `A' used as a template"
> A a(A::A<double>()); // "'A' is not a template" (Not?)
> // Should this work?
See section 14.5.2p5. The note points out that "because the explicit
template argument list follows the function template name, and because
conversion member function templates and construction member function
templates are called without using a function name, there is no way to
provide an explicit template argument list for these function
templates." Notes are not normative, but this one is merely putting
together the consequences of normative wording elsewhere in the
standard.
Therefore, it's always an error to declare a templated constructor whose
parameters can never be implicitly deduced (as in this case).
---
[ 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: Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
Date: 2000/07/09 Raw View
Christopher Eltschka <celtschk@physik.tu-muenchen.de> writes:
| Assuming I have the following class:
|
| class A
| {
| public:
| template<class T> A();
| };
|
| and now I want to declare an object using A::A<double>().
You cannot. Otherwise you'll name the constructor. But you'll
certainly agree with me that constructors are unnamed entities
(12.1/1).
--
Gabriel Dos Reis, dosreis@cmla.ens-cachan.fr
---
[ 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: "HT" <ht@labyrinth.net.au>
Date: 2000/07/11 Raw View
Christopher Eltschka <celtschk@physik.tu-muenchen.de> wrote in message
news:3965E0DF.A7F8B17E@physik.tu-muenchen.de...
> Assuming I have the following class:
>
> class A
> {
> public:
> template<class T> A();
> };
>
You cannot template class like that. Here is what it should have look like:
template<class T>
class A
{
public:
A();
void B();
};
template<class T>
A<T>::A()
{
// init members
}
template<class T>
void A<T>::B()
{
// some method
}
> and now I want to declare an object using A::A<double>().
> What is the correct way?
>
> Some tries, and what g++ tells me:
>
> A<double> a; // "non-template type `A' used as a template"
> A a<double>; // g++ doesn't complain about the <double>,
> // but claims there's no A::A() it could use.
> // So, is this correct syntax and compiler bug,
> // or wrong syntax and misleading message?
> A a(A<double>()); // "non-template type `A' used as a template"
> A a(A::A<double>()); // "'A' is not a template" (Not?)
> // Should this work?
>
> ---
To declare an object of type double or any other primitives or Abstract Data
Types, you simply declare it as follow:
A<double> MyDoubleObject;
or
A<string> MyStringObject;
or
A<double>* pDoubleObject = new A<double>();
---
[ 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: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 2000/07/08 Raw View
Assuming I have the following class:
class A
{
public:
template<class T> A();
};
and now I want to declare an object using A::A<double>().
What is the correct way?
Some tries, and what g++ tells me:
A<double> a; // "non-template type `A' used as a template"
A a<double>; // g++ doesn't complain about the <double>,
// but claims there's no A::A() it could use.
// So, is this correct syntax and compiler bug,
// or wrong syntax and misleading message?
A a(A<double>()); // "non-template type `A' used as a template"
A a(A::A<double>()); // "'A' is not a template" (Not?)
// Should this work?
---
[ 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 ]