My program was running smoothly until I needed my array to store into data types. After I ran the code the screen went blink and I could run my program again until I remove the into data type. Can sia force my array to store different data types? I really really need it to do this for my level renderer to be perfect.
An array with multiple data types
Okay, you might actually need to tell us which language you are using here (and what is an "into data type"? typo?)
You can do different data type arrays in Python, Ruby, PHP and JavaScript
Are you looking for something like a HashMap or Dictionary ?
If it's for something low level like a renderer, you might want to rethink some things for performance sake, Having multiple datatypes in a single array will require a lot of checking which is probably something you do not want.
We're missing a lot of information on what you actually want to achieve, but considering you are talking about a renderer, I assume you want to render different level objects? Perhaps consider having a renderable (or anything) base class that has a render function, but more info would be nice! :)
Bacterius already mentioned that knowing what the language you're working with is something nice to know, also what kind of data types you are referring to and what they should be doing to have your level renderer work.
I code in c++ and I really meant int data type but I got auto corrected.
You can cheat and use an array of pointers - however this can get very tricky to maintain and not recommended .
If it's for something low level like a renderer, you might want to rethink some things for performance sake, Having multiple datatypes in a single array will require a lot of checking which is probably something you do not want.
We're missing a lot of information on what you actually want to achieve, but considering you are talking about a renderer, I assume you want to render different level objects? Perhaps consider having a renderable (or anything) base class that has a render function, but more info would be nice!
Bacterius already mentioned that knowing what the language you're working with is something nice to know, also what kind of data types you are referring to and what they should be doing to have your level renderer work.
I code in c++ programming language. I need my array to hold 2 data types. int data type and a special one I don't feel like explaining. I need the int data type to be stored so my renderer can place my object correctly base on reading from numbers from a special file. Overall I just really need to store different data types in a array. This will be the only array to do this in my program.
If you mean each array element can either be an int or your other type, you can check out unions.
Basically youd have something like:
struct ArrayElement {
bool isThisAnObject; //use this to tell your code whether the type is MyObject or int so it can read/modify the correct one (assuming you cant deduce this some other way)
union { //object and integer overlap in memory/share some of the bytes, so you an only use one at a time or else face corruption of data
MyObject object;
int integer;
} data;
}
as the data type of the array. Note that all the elements of the array will be of size max(sizeof(MyObject),sizeof(int)) so you wont be saving any RAM by having some of the elements be int, AND you probably need to pay the extra byte to tell your code the actual type of each array element.
But it would be better if you give more information about the actual problem to see if theres some other more clean solution.