For all of your programming needs and wants.


    Class Type for GML/Javascript "var" in C++

    Share

    inegames
    Stranger
    Stranger

    Posts : 24
    Join date : 2009-05-05
    Age : 24
    Location : Im not sure

    Class Type for GML/Javascript "var" in C++

    Post by inegames on 5/19/2009, 11:27 pm

    I've been thinking about a class for "var" as you might see in GML or Javascript:
    eg:
    Code:
    var number;
    number = 0;
    number = string(number) + " - Now a string";
    (GML)

    How could such a class be written in C++?

    What I am thinking of right now, is something like:
    Code:
    class var {
    public:
     double d_value;
     int type;
     char* s_value;
     void set(double tosetto_v)
     {
      type = 0;
      d_value = tosetto_v;
     }
     void set(char* tosetto_v)
     {
      type = 1;
      s_value = tosetto_v; // I don't think this works, but im just showing my idea rather than making working code
     }
    }

    To use it, it would be something like:
    Code:
    int main()
    {
     var test;
     test.set("Hello!");
     system("cls");
     if(test.type == 1)
     {
      cout << test.s_value << "\n";
     }
     system("pause");
     return 0;
    }
    avatar
    Vivi_IX
    Stranger
    Stranger

    Posts : 38
    Join date : 2009-11-03
    Age : 27
    Location : USA: Painesville, Ohio

    Re: Class Type for GML/Javascript "var" in C++

    Post by Vivi_IX on 11/3/2009, 11:04 pm

    :/ C++ looks kinda complicated.
    avatar
    luke
    Admin
    Admin

    Posts : 194
    Join date : 2009-05-07
    Age : 23
    Location : Dallas, TX

    Re: Class Type for GML/Javascript "var" in C++

    Post by luke on 11/4/2009, 12:23 am

    XD C++ can be complicated. C is easier, but it doesn't have booleans >.>
    avatar
    SoulRed12
    Moderator
    Moderator

    Posts : 129
    Join date : 2009-05-08
    Age : 27
    Location : West-coast USA

    Re: Class Type for GML/Javascript "var" in C++

    Post by SoulRed12 on 11/4/2009, 1:01 am

    luke wrote:XD C++ can be complicated. C is easier, but it doesn't have booleans >.>
    *or classes

    Sponsored content

    Re: Class Type for GML/Javascript "var" in C++

    Post by Sponsored content


      Current date/time is 12/17/2017, 12:00 am