could someone pls give me a simple example of typename? how to use it?
could someone pls give me a simple example of typename? how to use it?
C++ use the keyword typename if you have a qualified name that refers to a type and depends on a template parameter. Only use the keyword typename in template declarations and definitions.
The following example illustrates the use of the keyword typename:
The statementCode:template<class T> class A { T::x(y); typedef char C; A::C d; }is ambiguous. It could be a call to function x() with a nonlocal argument y, or it could be a declaration of variable y withCode:T::x(y). C++ will interpret this statement as a function call. In order for the compiler to interpret this statement as a declaration, you would add the keyword typename to the beginning of it. The statementCode:type T::xis ill-formed. The class A also refers to A<T> and thus depends on a template parameter.Code:A::C d;
You must add the keyword typename to the beginning of this declaration:
You can also use the keyword typename in place of the keyword class in template parameter declarations.Code:typename A::C d;
murag sa akong nabasahan no , kay mo define kag name para reusable imong code..
ex.
typedef length= 69 ;
in your entire code imong gamiton is length na keyword so in case mausab ang value ni length, dili naka mag ukay-ukay sa imng code aron mag usab ni length, anha nalang ka sa imong declaration silbi..
mao siguro na
hehe
dili man siguro typedef angay gamiton sa above example kun dili #define. typename could be about the different data type in C++/C like int,float,char?
I gave the explanation above, this is the correct definition of typename.
Similar Threads |
|