RE: Explicitly specify template param of template ctor

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: MSalters (MSalters_at_discussions.microsoft.com)
Date: 01/03/05


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.



Relevant Pages

  • Re: Explicitly specify template param of template ctor
    ... What is the syntax for that? ... It would mean that template constructor functions ... > compared to other member functions. ... since a template specialization is selected by the ...
    (microsoft.public.vc.language)
  • Re: Explicitly specify template param of template ctor
    ... What is the syntax for that? ... It would mean that template constructor functions ... > compared to other member functions. ... since a template specialization is selected by the ...
    (microsoft.public.vc.language)
  • Re: Long long int
    ... > more to the syntax of GAS or AT&T or whatever assembly. ... but that is simple absurdity. ... trained monkeys could have come up with a better template. ... algebraic notation is clearly a win over AT&T's What-The-Fuck notation. ...
    (comp.lang.c)
  • Re: Open Office Writer as a source editor
    ... Vim's syntax coloring scheme ... works by assigning names to keywords, patterns, and regions. ... editors, you only need a keystroke or two to return to the definition ... One editor worked by having you fill in a template. ...
    (comp.lang.forth)
  • Re: Namelist Internal Read
    ... string to the parsing routinepreceded by a "template" of how I want ... part of the template is sort of obvious. ... and optional values for "substitutions" (need to define a syntax for ...
    (comp.lang.fortran)