RE: Explicitly specify template param of template ctor

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC 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: 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)
  • Re: Feedback wanted: new PHP template engine
    ... The last few months I've worked on making a template engine because ... at names) and is in many ways a simpler version of Smarty. ... I'm a really experienced Smarty user and i must say that i like your syntax more than the syntax Smarty uses. ... Ability to use objects in the template (not visible in the website or in the samples) ...
    (comp.lang.php)