RE: Explicitly specify template param of template ctor
From: MSalters (MSalters_at_discussions.microsoft.com)
Date: 01/03/05
- Next message: MSalters: "Re: Partial template function specialization"
- Previous message: Ravi Ambros Wallau: "Re: Is this impossible ? ReadFile"
- In reply to: Agoston Bejo: "Explicitly specify template param of template ctor"
- Next in thread: Thomas Mang: "Re: Explicitly specify template param of template ctor"
- Reply: Thomas Mang: "Re: Explicitly specify template param of template ctor"
- Reply: Agoston Bejo: "Re: Explicitly specify template param of template ctor"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 3 Jan 2005 03:13:01 -0800
"Agoston Bejo" wrote:
> Hello,
> suppose I've got a template constructor in a class, and I would like to
> explicitly specify one of its parameters. What is the syntax for that? Or is
> there no such syntax? It would mean that template constructor functions
> would have "narrower semantics" than ordinary member functions (by which I
> mean that they cannot be used in every way ordinary functions can ba used),
> which somehow feels "wrong" to me.
There's no such syntax. Constructors are special, anyway. They're not found
by name lookup, since they don't have names. That too is a restriction
compared to other member functions.
Furthermore, since a template specialization is selected by the
name<arguments> syntax, ctors indeed cannot be selected by name and
template arguments.
You may feel it's "wrong", but there's no obvious alternative. In code,
you can use a static member function:
class A {
int i;
public:
template< int I >
A ctor( ) {
A a;
a.i = I;
return a;
}
};
A obj = A.ctor<5>( );
Since this is a reasonable alternative, I can imagine why there's no
direct syntax.
- Next message: MSalters: "Re: Partial template function specialization"
- Previous message: Ravi Ambros Wallau: "Re: Is this impossible ? ReadFile"
- In reply to: Agoston Bejo: "Explicitly specify template param of template ctor"
- Next in thread: Thomas Mang: "Re: Explicitly specify template param of template ctor"
- Reply: Thomas Mang: "Re: Explicitly specify template param of template ctor"
- Reply: Agoston Bejo: "Re: Explicitly specify template param of template ctor"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|