I assume that you often work with hard to read template classes (like 90% of the STL).
Consider this code given the above assumption:
void foo(){ std::list<Class> myList; //...for(std::list<Class>::iterator iter = myList.begin();iter !+ myList.end()iter++){ //.. } std::tr1::smart_ptr<Class> myInstance(newClass()); }
This type of code layout can get very confusing very fast.
If you just add 3 typedef's at the beginning of this code, you'll make the code much easier to read.
typedefstd::list<Class> MyClassList;typedefstd::list<Class>::iterator MyClassIterator;typedefstd::tr1::shared_ptr<Class> MyClassPtr;
Using these typedefs, I'll show you what that code sample above will look like:
void foo(){ MyClassList myList; //...for(MyClassIterator iter = myList.begin();iter !+ myList.end()iter++){ //.. } MyClassPtr myInstance(newClass()); }
That's much better, isn't it?
No comments:
Post a Comment