Quote:
The compiler refuses to see them as a unspecialized type.
It can't; templates are a declaration that says what, for any given instantiation, may be the interface and implementation.
Quote:
But that's just the thing!
You can't even guess the type correctly and you think you know.
Quote:
In essence that you cannot use a class which hasn't been defined up to the point where you use it (it must be available on a previous line somewhere, thus "upwards".)
Wrong. You can. I do it everyday. You probably do it everyday you program in C++.
Quote:
Because then the compiler would be able to see all possible outcomes of the class CTest before the instantiation line. Thus it can parse all of those to see if it can find a match to its liking. Omitting them is the same as omitting half the definition of a class. Or would be. A specialization is part of the class CTest, part of the unspecialized class.
You know nothing of meta-programming. Any specializations aren't necessarily related by name, parameters, inheritance, interface, functionality, or even instantiation mechanism to the original template class.
Quote:
Right, but the idea was that the compiler could guess.
No. It can't. The compiler has to know or it's beyond useless.
Quote:
This is what shouldn't be. The compiler should be able to guess and try to resolve the ambiguity by checking the class and see if it can match a type. It shouldn't give up just because the instantiation is unspecialized.
That you think the compiler should determine a type by examination of an unrelated type makes all of your opinions invalid.
Quote:
There's only one unspecialized class, so search all parts of it
Wrong. There are potentially infinitely many unspecialized classes of any given template class.
Quote:
It can still resolve T to a type and then use the rules for best overloaded function to call. If it can't decide - then it will just return error - ambiguous.
The compiler knows it can't determine the templates arguments in such a way.
It is wrong.
Quote:
Code:
template<typename T> class CTest { CTest(const T*) {} };
int main()
{
CTest test("my test");
}
Quote:
it can translate T = char*
Quote:
the constructor becomes: CTest(const char*)
If 'T' became 'char *' the constructor would take a 'const char **'.
Quote:
And since there are two templates with the same constructor (one argument, T*), it will complain ambiguous.
You didn't answer the last question.
Quote:
Since only the second class matches the number of arguments in the list, it would instantiate the second and thus type = type_vector<char*, char*>.
You answered incorrectly. The parameter is not 'const T *'. The parameter is 'const char *'. The type from the template parameter list named 'T' is referenced only in the 'typedef' of 'type'. The template parameters can't be determined even by examining the template class 'CTest' in a typeless way as you apparently wish compilers did. That you tried to answer is sufficiently wrong.
Quote:
At least in the ideal compiler.
Then this "ideal" compiler couldn't compile any template code correctly.
Soma