65,187
社区成员




class A
{
public:
A();
~A();
virtual void fun(string str1, string str2) = 0;
}
class B: public A
{
public:
B();
~B();
virtual void fun(string str1, string str2)
{
cout << str1.c_str() << str2.c_str() << endl;
}
}
class C
{
public:
C();
~C();
……
void fun2(A* a);
……
protect:
typedef std::list<A*> A_LIST;
A_LIST m_alist;
typedef std::list<string> S_LIST;
S_LIST m_slist;
string m_str;
pthread_t m_metux;
……
}
C::fun2(A*a)
{
if(a == NULL)
return;
pthread_mutux_lock(m_metux);
m_alist.push_back(a);
m_alist.unique();
S_LIST:const_iterator iter = m_slist.begin();
for(; iter != m_slist.end(); ++iter) {
string idetity = (*iter);
a->fun(m_str, idetity);
}
}
int main(int argc, char ** argv)
{
A* p = new A;
// C::fun2(p);
return 0;
}
A* pA = new B;
C* pC = new C;
pC->fun2(pA);
class C
{
public:
C();
~C();
……
static void fun2(A* a);
……
protect:
typedef std::list<A*> A_LIST;
A_LIST m_alist;
typedef std::list<string> S_LIST;
S_LIST m_slist;
string m_str;
pthread_t m_metux;
……
}