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 17:21

>>18

C++ is meant to work however you want to make it work. That's the entire idea behind making it multiparadigm. Anyways, found a way that sort of works.... should probably use virtuals for a few things though, like >>17 suggested.

>>11
>>13

So... make = return the type of the class using it? Gotcha.

>>14

Any type of OOP you consider NOT harmful?

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