1

私は Android で C++ プロジェクトに取り組んでいます。私が達成したいのは、C++ で非同期呼び出しを行い、JNI 経由でデータを送り返すことです。これは単純な概念実証ですが、これは私の C++ の知識が限られていることも意味します。

私はすべての機能を動作させましたが、プロジェクトの C++ 側を「より良く」したいので、オブザーバー パターンを実装したいと考えています。これをチュートリアルとして使用しました: http://www.codeproject.com/Articles/328365/Understanding-and-Implementing-Observer-Pattern-in

すべてを追加した後 (私のプロジェクトに変更された ofc)、次のコンパイル エラーが発生します。

std::vector<PoCCplusplus*> list;

件名 h と cpp:

#pragma once
#include <vector>
#include <list>
#include <algorithm>
#include "PoCCplusplus.h"


class ASubject
{
    //Lets keep a track of all the shops we have observing
    std::vector<PoCCplusplus*> list;

public:
    void Attach(PoCCplusplus *cws);
    void Detach(PoCCplusplus *cws);
    void Notify(char *xml);
};

#include "ASubject.h"

using namespace std;

void ASubject::Attach(PoCCplusplus *cws)
{
    list.push_back(cws);
}
void ASubject::Detach(PoCCplusplus *cws)
{
    list.erase(std::remove(list.begin(), list.end(), cws), list.end());
}

void ASubject::Notify(char *xml)
{
    for(vector<PoCCplusplus*>::const_iterator iter = list.begin(); iter != list.end(); ++iter)
    {
        if(*iter != 0)
        {
            (*iter)->Update(xml);
        }
    }
}

それはおそらく私が見逃している本当に単純なものですが、その解決策を見つけることができません。

4

3 に答える 3