Typename in c++
_______________________________________________________________________
“typename” keyword tells the compiler to interpret a particular name as a type and that type is nested into another type.
#include <iostream>
using namespace std;
class A
{
public:
class InnerA
{
public:
void Show();
};
};
void A::InnerA::Show()
{
cout<<"Inside show() of InnerA class\n";
}
template <class T>
class Container
{
private:
typename T::InnerA ia;
public:
void ShowContainer()
{
ia.Show();
}
};
int main()
{
Container<A> con;
con.ShowContainer();
}
Note: “typename” keyword can be used in place of class in template declaration.
Exapmle:
template <class T>
class Container
{};
Can be decalred as
template <typename T>
class Container
{};
_______________________________________________________________________
Copyright © Open Sky Technology |
Corporate Office: #4, RR Complex, 2nd Floor, Munnekolala, Marathahalli, Bangalore – 560037. (Landmark: near Munnekolala Bus Stop) Mobile: 9886333765,