typedef std::list<LDAPCtrl> CtrlList;
typedef CtrlList::const_iterator const_iterator;

please help me in understanding the above typedef statements as we know that typedef syntax is,
typedef <attributes> datatype aliasname

Thanks.

Recommended Answers

All 3 Replies

typedef specify a synonym for a type. You can use typedef declarations to construct shorter or more meaningful names for types already defined by the language or for types that you have defined.
Read
http://msdn.microsoft.com/en-us/library/05w82thz(VS.71).aspx

Typedef's are likely to be a lot related with Macro's,
Though there is a huge difference between Macro's and Typedef's

Macro's follow a " find and replace " mechanism before the code is actually compiled.

Typedef's almost do the same thing but instead of find and replace, they are much like a "ALIAS" or "A.K.A"
Basically they give another name to a pre-existing statement.

typedef std::list<LDAPCtrl> CtrlList;

This first typedef specifies the compiler to give std::list<LDAPCtrl> a name of CtrlList So the next time you declare a CtrlList ,

CtrlList biglist;

is equivallent to

std::list<LDAPCtrl> biglist

So That way we do-not need to specify everything again.

Now lets consider the second statement.

typedef CtrlList::const_iterator const_iterator;

Now we specify that CtrlLIST::const_iterator which is again equivallent to std::list<LDAPCtrl>::const_iterator to be accessible by just a simple name of const_iterator

many thanks to all of u for ur kind responses.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.