Restrictions for Nontype Template Parameters
Note that nontype template parameters carry some restrictions.
In general, they may be constant integral values (including enumerations) or
pointers to objects with external linkage.
Floating-point numbers and class-type objects are not allowed
as nontype template parameters:
Not being able to use floating-point literals (and simple
constant floating-point expressions) as template arguments has historical
reasons. Because there are no serious technical challenges, this may be
supported in future versions of C++.
Because string literals are objects with internal linkage (two
string literals with the same value but in different modules are different
objects), you can't use them as template arguments either:
You cannot use a global pointer either:
However, the following is possible:
The global character array s is initialized by
"hello" so that s is an object with external linkage.
-----------------------------------------------------------------
See Also:
-----------------------------------------------------------------
See Also:
-----------------------------------------------------------------
- Complete Tutorial of C++ Template's
- Standard Template Library Tutorial
- Inter Process Communication Tutorial
- Advance Programming in C & C++
-----------------------------------------------------------------
No comments:
Post a Comment