Archived

This topic is now archived and is closed to further replies.

copying information

This topic is 5313 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Scrolling through some source in the Ogre engine (ogre.sourceforge.net) I see some code I have not seen before. A template object is created in a plugin dll and stored in a container for types of objects from which the plugin class has inherited from for later. Later on, a base class of the object is created and then *sys = *pTemplate; is called, sys being the object and pTemplate being the plugin class. This puts the properties of the template into the object. Here is some code:
// in engine

class CBase
{
blah, blah, blah;
};

// in plugin dll

class CPlugin : public CBase
{
blah, blah, blah;
};

extern "C" void StartPlugin();
{
CBase* pPlugin;
pPlugin = new CPlugin();
PluginSingleton.AddPlugin(pPlugin);
}

// in engine

CBase* CPluginManager::CreatePlugin(string name, string template)
{
CBase* pTemplate = TemplateMap[template];
CBase* pPlugin = CreatePlugin(name)
*pPlugin  = *pTemplate;
return pPlugin;
}
It makes sense when I look at it now but I have never seen the technique and I thought it wouldn''t work because of referencing the same memory address but it doesn''t because it is simply copying the information to a new address. Does anyone know some places to learn more little techniques like this? PS. I guess my own message explained the problem to me. At the start of the post I saw *sys = *pTemplate; as &sys = &pTemplate;. I guess that is because you write classx* x = &otherx;

Share this post


Link to post
Share on other sites