Allocating using a pointer will compile, but I wouldn't do it that way. You should only use pointer types when absolutely necessary.
Pointer types are initialized as you showed in your example: MyClass *obj = new MyClass(); This will allocate the memory for MyClass dynamically on the heap. Heap-allocated memory needs to be released by using the delete operator like so: delete obj;
Note that if you're allocating an array of objects, say MyClass *objs = new MyClass[]; you will need to use a different form of the delete operator to de-allocate (ie, free/release) all objects in the array: delete [] objs; The [] indicates that you're releasing an array,
not just the first object the array points to.
Objects can also be initialized the way Ryouken said: MyClass obj; will initialize an object of type MyClass on the stack using the default constructor. Stack-allocated memory is (if i recall correctly) managed in the process space and will be freed automatically on program
termination, so you won't need to call delete when objects are instantiated this way (in fact, the compiler will throw an error when you try to delete a non-pointer type). This is the way you should probably be doing it.
Accessing members for pointers is done with the arrow operator, that I'm sure you're familiar with: MyClass *obj = new MyClass(); x = obj->Member;
Accessing members for non-pointers uses the dot operator: MyClass obj = MyClass; x =obj.Member;
If you dynamically allocate memory in a class (ie use the new keyword), remember to call delete in your class's destructor.
Looking at the way you do it with the map is completely valid to the compiler. However, that's a terrible way to solve the problem and has so much overhead for something that is built into the language as a feature. If you want, I'd be happy to look over your code to double-check for memory
leaks if you want a second set of eyes on your code.
---
class EOSERV {
Programmer | Oldbie
Open source EO Client: https://github.com/ethanmoffat/EndlessClient
};