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:33

>>22
I'm not doing prototype OO though. [...] The only thing I can't do
The only thing you can't do is what everyone does with Ruby: treat it like a proto-OO system.

Since Ruby is a dynamic language it isn't hard to support monkey patching classes (at the cost of performance.) This is how eg. rails works. You can't provide an object system in C++ that comes anywhere near approximating the way people use Ruby, where every framework piles its crap into the base classes. It's why Ruby is so slow (look at benchmarks that don't use rails vs. ones that do.)

Why don't you just stop using C++? There are a lot of other languages out there that have different type/object systems. In fact in some languages what you're trying to do is considered quite acceptable instead of downright terrible.

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