Как использовать класс контейнера в классе Item, если он еще не определен ⇐ C++

Программы на C++. Форум разработчиков
Anonymous
Как использовать класс контейнера в классе Item, если он еще не определен

Сообщение Anonymous »

У меня есть класс элементов CItem и класс контейнера CListOfTables, который включает подчиненный класс контейнера CTable (и этот класс включает элементы). Для некоторой функции Aktualizuj() (функция, которая изменила имя элемента) мне нужно передать ссылку на подчиненный класс.
Но когда я пытаюсь объявить функцию в классе CItem, я не знаю класс ни CListOfTables, ни CTable.
Я мог бы объявить класс CListOfTables:
class CListOfTables;

но нет CListOfTables::CTable:
class CListOfTables::CTable; //makes error

Есть ли какое-нибудь умное решение для этой проблемы?
КОД:
// C++ program to read from a file
#include
#include
#include
#include
#include "set"
#include

using namespace std;

struct CItem
{
protected:
wstring m_wsText;

public:

//Konstruktory
protected:
CItem(LPCTSTR lsText) : m_wsText(lsText ? lsText : L"") {}
CItem() = default; //emty konstruktor

public:
//Vrátí seznam tras v mapě jako řetězec názvů tras, oddělěný čárkami
LPCTSTR GetText() const { return m_wsText.data(); }
void SetText(LPCTSTR lsTxt) { m_wsText = lsTxt; }
size_t GetTextSize() const { return m_wsText.size(); }

//Here I need send CListOfTables::CTable to function because of I need actualize an Item in std:set,
// but CListOfTables::CTable has not yet been defined
inline bool Aktualizuj(CListOfTables::CTable* tbl, CItem* pCopy);

};

//Conteiner class o CTable
class CListOfTables
{

public:
//Container of CItem
class CTable : public set
{

protected:
CTable() = delete;
CTable(const CTable& druhy) = delete; //kopírovací konstruktor
void operator=(const CTable& kopie) = delete; //operátor přirazení

}; // CTable

// Atributes of CListOfTables
protected:
CTable m_sezOfTables[3];

public:
CTable& GetTbl(int iType)
{
return m_sezOfTables[iType];
}
}; //class CSezTblPopisu

int main()
{

}

inline bool CItem::Aktualizuj(CListOfTables::CTable* tbl, CItem* pCopy)
{
if (wcscmp(GetText(), pCopy->GetText()) == 0)
return;

auto it = tbl->find(this);
if (it != tbl->end())
{
CItem* item = *it;
tbl->erase(it);
item->SetText(pCopy->GetText());
tbl->insert(item);
return true;
}
else
return false;
}


Подробнее здесь: https://stackoverflow.com/questions/790 ... efined-yet

Вернуться в «C++»