Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

typerdef in class template

Status
Not open for further replies.

isaisa

Programmer
May 14, 2002
97
IN
Hi all
i am going through reading pahse for C++ templates where i came across some doubts .

1] The code snippet to which i came across in the document is as follows


Code:
         template <typename T>
            class CTest {
                 public:
                     typedef int I;
            };


what is the use of declaring the typedef inside the class template. what is the scope for the typedef ? is this typedef restricted to the class definitions and their instances or it can be protected to the outside world with the access specifiers as protected and privete?

2] When the Argument Dependent Lookup comes in to play in the templates ? this is not very clear when i came across some words like unqualified dependent names .... help in understanding this ADL concept would be of great help in understanding the templates for me ...


thanks in advance

sanjay
 
1. Inner typedef name is the same as for other names in a class declaration. Yes, this public typedef can be accessed outside template class, for example:
Code:
CTest<int>::I  i = 0; // or
CTest<char>::I j - 1;
i = j; // it's OK, int to int...
Of course, this typedef (all typedefs) name is not a new type name: it's an alias for int. Yes, you may protect this typename (make it protected or private) - as usually for class member names. You may use CTest<type>::I where you can see this template declaration.

2. Sorry, but I have no time now. May be, later (tomorrow?)...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top