How can I replicate the above behavior

Hello c++.com!

I used Game Maker, but the limitations anoyying, so I decided to switch to c++. There is great tutorials, and I can replicate most of the behavior, but I lack the knowledge to do two things:

1. How GM can make variables story any type?
2. How ds_grid-s working (they are similar to 2D arrays, but can hold any type of value and vary in size dinamically)

Is there anybody, who know, how I can do this?

Thanks for your help!
1. templates, unions or void pointers

1
2
3
4
5
6
7
8
template<typename T>
class wrapper
{
   public:
      //ctors, dctor, functions and overloaded operators
   private:
      T data;
};


1
2
3
4
5
6
7
8
9
10
union variable
{
    int short _int_16;
    int long  _int_32;
    int long long _int_64_;
    float decimal;
    double _d_decimal;
    char character;
    wchar_t wide_character;
};


1
2
int number=new int(500);
void * ptr=number; //can point to any variable 


2. vectors (dynamic arrays)

1
2
std::vector<int> numbers;
numbers.push_back(50); //adds number in the vector 

Last edited on
Thanks for the quick answer.
I'll look into it, uninons and vectors are not new ,but never used them, but void pointers are entirelly new!

Thanks for your help again!
Templates should be strongly preferred over unions and void pointers.
Topic archived. No new replies allowed.