W programie mam takie klasy:
#include <iostream>
class Stos;
class Element
{
protected:
Element* next;
public:
Element() : next (0) {};
Element(const Element & e);
friend class Stos;
};
class Liczba : public Element
{
private:
double el;
public:
Liczba(double l);
Liczba(double l, Element* e);
const double pokaz_l() { return el; }
virtual void przetwarzaj(Stos & s);
};
class Dzialanie : public Element
{
private:
char el;
public:
Dzialanie(char z);
Dzialanie(char z, Element* e);
const double pokaz_z() { return el; }
virtual void przetwarzaj(Stos & s);
};
class Stos
{
private:
Element* top;
int count;
public:
Stos() : top(0), count (0) {};
~Stos();
// Stos(const Stos & s);
// Stos& operator=(const Stos & s);
void put(Element* e);
// Element* pop();
// Element & showTop();
// void pokaz_caly();
// Stos& reverse();
friend class Element;
friend class Liczba;
friend class Dzialanie;
};
Chcę teraz stworzyć uniwersalną funkcję put(), która będzie kładła na stos obiekt niezależnie od tego czy jest on Liczbą czy Działaniem - innymi słowy, ma kłaść Element. Mniej więcej tak:
void put(const Element * e)
{
1. pobierz aktualną wartość top
2. skopiuj e i przypisz e.next=top
3. połóż e jako top
}
Brak mi pomysłu jak dokładnie to zrobić, proszę o wskazówki.