A
Agoston Bejo
Platform: VC++ 7.1
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 be used), which
somehow
feels "wrong" to me.
An example:
------------------------------
#include <iostream>
using namespace std;
struct A {
template<int N, typename T>
A(T t1, T t2) {
i = (int)t1 + (int)t2 + N;
}
int i;
};
int _tmain(int argc, _TCHAR* argv[])
{
A a<5>(7.5, 8.5); // ERROR
cout << a.i << endl;
return 0;
}
--------------
Error messages: (both for the same line)
error C2143: syntax error : missing ';' before '<'
error C2512: 'A' : no appropriate default constructor available
Thx,
Agoston
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 be used), which
somehow
feels "wrong" to me.
An example:
------------------------------
#include <iostream>
using namespace std;
struct A {
template<int N, typename T>
A(T t1, T t2) {
i = (int)t1 + (int)t2 + N;
}
int i;
};
int _tmain(int argc, _TCHAR* argv[])
{
A a<5>(7.5, 8.5); // ERROR
cout << a.i << endl;
return 0;
}
--------------
Error messages: (both for the same line)
error C2143: syntax error : missing ';' before '<'
error C2512: 'A' : no appropriate default constructor available
Thx,
Agoston