The knowledge points of C ++ are fragmented and tedious, but they do not have any effect in conclusion. More problems should be found in practice. Today, I wrote the implementation code for linear tables in "data structures, algorithms, and application C ++ language descriptions", and I feel a lot unfamiliar with the ability to write code.
During the compilation process, I found several issues that are worth noting:
1. My code is written through a class template. Many people put declarations and implementations in a header file when writing code. primer says that export can be used for separate compilation. I am not very familiar with this, but I got it by using two # ifndef .... # endif achieves the statement placed in. h. The implementation is placed in. cpp.
2. In the template class, you must add <> to the Declaration for <, or else the compilation fails.
3. cout refresh. For example, for fun (int & x), if we use cout <fun (y) <y; the screen does not display the updated value of y, instead, it calls the value before y. It is correct to divide it into two cout for output, or refresh the output.
Okay, paste the code: implement the environment vs2010
MY_LINEARLIST_H<ostream> < T> cap = ~ find( pos, T& hold) search( T& x) <T>& drop( pos, T&<T>& insert( pos, T& printt(ostream& os)& << (ostream& os, LinearList<T>&*
MY_LINEARLIST_CPP<cstdlib><ostream>< T><T>::LinearList(= == < T><T>::~LinearList( (element !=< T> LinearList<T> size == < T> LinearList<T>< T> LinearList<T>::find( pos,T& hold) (pos > size || pos < ) = element[pos- < T> LinearList<T>::search( T& x) ( i=; i<size; ++ (element[i] = i+ < T><T>& LinearList<T>::drop( pos, T& (pos > size || pos < = element[pos-( i=pos; i<size; ++-] =-- *< T><T>& LinearList<T>::insert( pos, T&(size ==* newElement = T[capacity*<<= ( i=; i<pos; ++-] = element[i-=( i=pos; i<size; +++] =++=( i=size; i>=pos; --= element[i--] =++ *< T> LinearList<T>::printt(ostream& ) ( i=; i<size; ++ << element[i] << < T>& << (ostream& , LinearList<T>&);
LinearList<> L( y= L.insert (, cout << L << L.insert (, cout << L << L.insert (, cout << L << cout << << y << cout << << L.find(,y) << << y << cout << << y << }