If you do this:
BaseComponent *component = new DerivedComponent;
BaseComponent notAPointer = *component;
You are 'slicing' the object.
How many files is your project? If it's only two or three files, could you upload them to someplace like Ideone.com, and post the links, so we can see the entire code? I feel like I'm looking at a puzzle with half the pieces missing.
Yeah I know about the slicing problem, but It should be fine right? as its just basepointer that points to a derived pointer, and when I try to retrieve the component I just cast it upwards again.
template<class T_S>
T_S* GetComponent_S()
{
std::string test = typeid(T_S).name();
std::map<std::string,BaseComponent*>::iterator it;
//"Class" + " "
for(int i = 0; i < 6 ;i++)
{
test.erase(test.begin());
}
it = ComponentList_S.find(test);
if(it != ComponentList_S.end())
{
T_S* ptTComponent;
ptTComponent = (T_S*)it->second;
return ptTComponent;
}
else
return NULL;
//*/
}
And I don't mind uploading my project, but I don't think you want me to :l seeing as there's about 56 files, but most of files is not related toward this,and its probably one of the uggliest thing you ever see in you lifetime :x. as this project is just a learning project for me. Where I have been doing "crazy" and stupid stuffs, to help me try understanding coding.
But I think I solved the problem now, Instead of having a vector<Entity> I just made it a vector<Entity*> to prevent it from copying a dead object.
if you still want me to upload it I can or perhaps just the files that you may want?, and am still intresterd in knowing why I get that error as it may help me prevent myself from doing the same in the future.
P.S
if it matter I get this same reading violation adress 0xfeeefeee.
P.S.S
Another theory which may be the problem
When I use this code
Global->EntityController.NewEntity_S("blan");
It will Trigger
void EntityHandler::NewEntity(std::string name)
{
Entity testing;
testing.name = name;
TotalEntity.push_back(testing);
}
Here the testing entity gets push_back into the Vector, but the vector "copies" the entity. so after the end of this function, testing will die, so it will call upon the destructor. Seeing as the destructor is been call upon, it will free the memory of the transformcomponent that gets added in the constructor.
So when the program ends it will try to delete the same memory, which already been deleted. and seeing how its "technially" two diffrent object, like twin. the testing transform component gets "zero-fied"(Not sure if this is even a word, I mean that the pointer gets equal to = 0 ), the second twin doesn't as it copies the state of the other twin before it.
Which explains why when I made the vector from <Entity> to <Entity*> it suddenly works again, cause the same memory adress only gets "deleted" once.
P.SSS
if the text made no sense is that when I was going to upload the idea struck me and I started write this second section :x. sorry for all the confusingness.
oh while am at it.
If we say that I still want to go with a vector<Entity> instead of pointers version, what is a good idéa to prevent this? seeing that it won't work just to see if the pointer is null or not. is there a way to check if its possible to see if a certain adress already been deleted?