For all of your programming needs and wants.

  • Post new topic
  • Reply to topic

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

Share

inegames
Stranger
Stranger

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

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

Post by inegames on 5/19/2009, 10: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;
}

Vivi_IX
Stranger
Stranger

Posts: 36
Join date: 2009-11-04
Age: 19
Location: USA: Painesville, Ohio

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

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

:/ C++ looks kinda complicated.

luke
Admin
Admin

Posts: 156
Join date: 2009-05-08
Age: 15
Location: Dallas, TX

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

Post by luke on 11/3/2009, 11:23 pm

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

SoulRed12
Moderator
Moderator

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

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

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

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

*or classes
  • Post new topic
  • Reply to topic

Current date/time is 11/24/2009, 10:59 pm