模板成员函数无法单独放在一个文件内,因此需要放在同一个头文件内
parent
0ff74f30c7
commit
b84c41cdd2
|
@ -3,40 +3,5 @@
|
|||
//
|
||||
|
||||
#include "Observer.h"
|
||||
template<typename T>
|
||||
int Observed<T>::AddObserver(Observer<T> *p) {
|
||||
if(nullptr == p){
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(typename std::vector<Observer<T>*>::iterator itr = m_vObservers.begin();
|
||||
itr != m_vObservers.end();itr++){
|
||||
if(((Observer<T>*)*itr) == p){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
this->m_vObservers.push_back(p);
|
||||
return 0;
|
||||
}
|
||||
template<typename T>
|
||||
int Observed<T>::DeleteObserver(Observer<T> *p) {
|
||||
for(typename std::vector<Observer<T>*>::iterator itr = m_vObservers.begin();
|
||||
itr != m_vObservers.end();itr++){
|
||||
if(((Observer<T>*)*itr) == p){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
template<typename T>
|
||||
int Observed<T>::NoticeObserver(T *p) {
|
||||
if(nullptr == p){
|
||||
return -1;
|
||||
}
|
||||
for(typename std::vector<Observer<T>*>::iterator itr = m_vObservers.begin();
|
||||
itr != m_vObservers.end();itr++){
|
||||
((Observer<T>*)*itr)->OnNotifyData(p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,5 +27,40 @@ public:
|
|||
private:
|
||||
|
||||
};
|
||||
template<typename T>
|
||||
int Observed<T>::AddObserver(Observer<T> *p) {
|
||||
if(nullptr == p){
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(typename std::vector<Observer<T>*>::iterator itr = m_vObservers.begin();
|
||||
itr != m_vObservers.end();itr++){
|
||||
if(((Observer<T>*)*itr) == p){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
this->m_vObservers.push_back(p);
|
||||
return 0;
|
||||
}
|
||||
template<typename T>
|
||||
int Observed<T>::DeleteObserver(Observer<T> *p) {
|
||||
for(typename std::vector<Observer<T>*>::iterator itr = m_vObservers.begin();
|
||||
itr != m_vObservers.end();itr++){
|
||||
if(((Observer<T>*)*itr) == p){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
template<typename T>
|
||||
int Observed<T>::NoticeObserver(T *p) {
|
||||
if(nullptr == p){
|
||||
return -1;
|
||||
}
|
||||
for(typename std::vector<Observer<T>*>::iterator itr = m_vObservers.begin();
|
||||
itr != m_vObservers.end();itr++){
|
||||
((Observer<T>*)*itr)->OnNotifyData(p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif //GENERAL_OBSERVER_H
|
||||
|
|
Loading…
Reference in New Issue