templatized class inside templatized class

This is a discussion on templatized class inside templatized class within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by -EquinoX-
I think the only way I can restraint it is for the template class vector to ...

I think the only way I can restraint it is for the template class vector to take an object type... type can be anything but then I can guarantee that type has all the overload operators

If you really want to make sure that vector's element type can support all the operators, then the solution is to create a vector class and an element class. Note, classes, not class templates. Once you involve templates, it becomes possible to try to instantiate the template with a type that does not support the operations required.

Originally Posted by -EquinoX-

well it's a requirement for both the vector and the type parameter... I am only confused on how can I make so that whatever type is the parameters then it would support those operators

Assume that the type supports those operators and thus make use of them. The compiler will then enforce this requirement for you by spitting out an error if the user attempts to call a function that assumes that a particular operator is available when it is not.

If you really want to make sure that vector's element type can support all the operators, then the solution is to create a vector class and an element class. Note, classes, not class templates. Once you involve templates, it becomes possible to try to instantiate the template with a type that does not support the operations required.

if he doesn't use templates, then he can't actually use the operators at all can he?

All objects of built-in types can be initialised with an int or have an int assigned to them, but they do not actually have constructors. For class types, it depends on the class type. As I noted, some class types are deliberately designed as numeric types and thus have similiar behaviour in many respects, e.g., the std::complex class template.