// c++

#include <iostream>

class base {
public:
    enum TYPE { I = 26, F = 369 };

    base(TYPE t) : type(t) {};
    virtual void show() = 0;

    static base* create(int);
    static base* create(float);

    void is_what() {
        std::cout << "is ";
        switch(type) {
        case I: std::cout << "I"; break;
        case F: std::cout << "F"; break;
        default: std::cout << "?"; break;
        }
        std::cout << std::endl;
    }
  private:
    TYPE type;
    base() {};
};

class i : public base {
  public:
    void show() { std::cout << "int value: "
                        << n << std::endl; }
  private:
    friend class base;
    i(int val) : base(I), n(val) {};
    int n;
};

class f : public base {
  public:
    void show() { std::cout << "float val: "
                       << n << std::endl; }
  private:
    friend class base;
    f(float val) : base(F), n(val) {};
    float n;
};

base* base::create(int n) {
    return new i(n);
}

base* base::create(float n) {
    return new f(n);
}

int main() {
    base* b1 = base::create(67);
    base* b2 = base::create(0.675f);

    b1->show();
    b1->is_what();
    b2->show();
    b2->is_what();

    return 0;
}
_______________________________________________
NetBehaviour mailing list
NetBehaviour@netbehaviour.org
http://www.netbehaviour.org/mailman/listinfo/netbehaviour

Reply via email to