模板成员函数无法单独放在一个文件内,因此需要放在同一个头文件内

master
a7458969 2019-12-22 01:45:25 +08:00
parent 0ff74f30c7
commit b84c41cdd2
2 changed files with 35 additions and 35 deletions

View File

@ -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;
}

View File

@ -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