为今天而努力的人很平凡,为昨天而努力的人叫失败,只有为美好明天而战斗不止才叫精彩!
分类: C/C++
2013-06-27 17:17:46
template template |
template void print2nd(const C& container) // container; { // this is not valid C++! if (container.size() >= 2) { C::const_iterator iter(container.begin()); // get iterator to 1st element ++iter; // move iter to 2nd element int value = *iter; // copy that element to an int std::cout << value; // print the int } } |
template void print2nd(const C& container) { C::const_iterator * x; ... } |
template void print2nd(const C& container) { if (container.size() >= 2) { C::const_iterator iter(container.begin()); // this name is assumed to ... // not be a type |
template void print2nd(const C& container) { if (container.size() >= 2) { typename C::const_iterator iter(container.begin()); ... } } |
template void f(const C& container, // typename not allowed typename C::iterator iter); // typename required |
template class Derived: public Base // base class list: typename not public: // allowed explicit Derived(int x) : Base { // init. list: typename not allowed typename Base ... // name not in a base class list or } // as a base class identifier in a ... // mem. init. list: typename required }; |
template void workWithIterator(IterT iter) { typename std::iterator_traits ... } |
template void workWithIterator(IterT iter) { typedef typename std::iterator_traits value_type temp(*iter); ... } |