Sha256: 9cb920a8288593351d02a48b6ca7e86e231de313ad29cce910de6b12efa7449a

Contents?: true

Size: 1.35 KB

Versions: 38

Compression:

Stored size: 1.35 KB

Contents

#include "rice/Data_Type.hpp"
#include "rice/Constructor.hpp"

using namespace Rice;

class Organism
{
public:
  virtual ~Organism() = 0;
  virtual char const * name() = 0;
};

Organism::
~Organism()
{
}

class Animal
  : public Organism
{
public:
  virtual ~Animal() = 0;
  virtual char const * speak() = 0;
};

Animal::
~Animal()
{
}

class Bear
  : public Animal
{
public:
  virtual char const * name()
  {
    return "Bear";
  }

  virtual char const * speak()
  {
    return "I'm smarter than the average bear";
  }
};

class Dog
  : public Animal
{
public:
  virtual char const * name()
  {
    return "Dog";
  }

  virtual char const * speak()
  {
    return "Woof woof";
  }
};

class Rabbit
  : public Animal
{
public:
  virtual char const * name()
  {
    return "Rabbit";
  }

  virtual char const * speak()
  {
    return "What's up, doc?";
  }
};

extern "C"
void Init_animals(void)
{
  RUBY_TRY
  {
    define_class<Organism>("Organism")
      .define_method("name", &Organism::name);

    define_class<Animal, Organism>("Animal")
      .define_method("speak", &Animal::speak);

    define_class<Bear, Animal>("Bear")
      .define_constructor(Constructor<Bear>());
      
    define_class<Dog, Animal>("Dog")
      .define_constructor(Constructor<Dog>());

    define_class<Rabbit, Animal>("Rabbit")
      .define_constructor(Constructor<Rabbit>());
  }
  RUBY_CATCH
}

Version data entries

38 entries across 38 versions & 6 rubygems

Version Path
rice-3.0.0 sample/inheritance/animals.cpp
rice2-2.2.1 sample/inheritance/animals.cpp
rice2-2.2.0 sample/inheritance/animals.cpp
rice-2.2.0 sample/inheritance/animals.cpp
rice-2.1.3 sample/inheritance/animals.cpp
rice-2.1.2 sample/inheritance/animals.cpp
rice-2.1.1 sample/inheritance/animals.cpp
rice-2.1.0 sample/inheritance/animals.cpp
rice-2.0.0 sample/inheritance/animals.cpp
rice-1.7.0 sample/inheritance/animals.cpp
rice-1.6.3 sample/inheritance/animals.cpp
jameskilton-rice-1.2.0 sample/inheritance/animals.cpp
rice-1.6.2 sample/inheritance/animals.cpp
rice-1.6.1 sample/inheritance/animals.cpp
rice-1.6.0 sample/inheritance/animals.cpp
rice-1.6.0.pre sample/inheritance/animals.cpp
rice-1.5.3 sample/inheritance/animals.cpp
rice-1.5.2 sample/inheritance/animals.cpp
keyme-rice-1.5.1.keyme1 sample/inheritance/animals.cpp
keyme-rice-1.5.1.keyme sample/inheritance/animals.cpp