Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Pure OOP Sepples

Name: Anonymous 2011-12-25 21:23

Basically, trying to define a set of types to replace the standard int, char, float, etc... to make C++ more like Ruby. This is what I have so far... not sure what to name a namespace other than perhaps POOP (Pure Object Oriented Programming... obviously very unprofessional), so I haven't tossed them in a namespace yet.

#include <stdint.h>
#include <string>
#include <sstream>

class Int_Obj {
        int32_t Data;
        Int_Obj(int32_t argument) { Data = argument; }
public:

        Int_Obj() {}
   
        Int_Obj operator + (int32_t arg) { return Int_Obj(arg + Data); }
        Int_Obj operator + (Int_Obj arg) { return Int_Obj(arg.Data + Data); }
        Int_Obj operator - (int32_t arg) { return Int_Obj(Data - arg); }
        Int_Obj operator - (Int_Obj arg) { return Int_Obj(Data - arg.Data); }
   
        void operator =  (int32_t arg) { Data = arg; }
        void operator =  (Int_Obj arg) { Data = arg.Data; }
        void operator += (int32_t arg) { Data += arg; }
        void operator += (Int_Obj arg) { Data += arg.Data; }
        void operator -= (int32_t arg) { Data -= arg; }
        void operator -= (Int_Obj arg) { Data -= arg.Data; }
        void operator ++ () { Data++; }
        void operator -- () { Data--; }

        std::string to_s() {
                std::ostringstream out;
                out << Data;
                return out.str();
        }
};


Anyways, any suggestions on what else I might need to add, or how to implement things like Ruby's arrays (can store any number of any types of objects, and are safe from memory leaks)... obviously void pointers aren't exactly an option.

Name: Anonymous 2011-12-26 18:11

>>20

I'm not doing prototype OO though. I'm wrapping all the basic data types in classes and giving them an ass load of methods to make them the C++ equivalent of Ruby Fixnum objects (or, alternatively, do to int, float and char what std::string did to char*). The only thing I can't do is shit like 5.to_s() or Fixnum.each { block_of_code }, because that's beyond the power of C++. Although I wish I could make an equivalent of the proc class, and have it store some function pointer (or anonymous function ala C++11), let it be aware of it's own arity, and have some call (bleh, ...) method.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List